How do i let my game react if i press on a button
Alright I’ll stop joking! This is really easy and more importantly really easy to search for. Watch some of the tutorials for the UI but this is the basics.
Create a script (I’ll use C# for this) and in that script create a public void function. It HAS to be PUBLIC so like this
public void PushTheButton()
{
print("You pressed my button");
}
leave Start() and Update() and the rest of your script as is just add that function. Save and drag the script onto the button. Then click on the button and look in the inspector.
Click + in the OnClick area of the button and a slot appears, drag your button onto the slot (even though the slot is on the button!). From the drop down select your script name → PushTheButton.
And that’s it, if you click on the button now it’ll call that function and do whatever is in it, in this case send “You pressed my Button” to the console.