How do i make UI buttons work?

New to this particular functionality. All ii want is to run some code, any code, when my button is clicked.

The inspector has a ton of options for onclick happenings of a button, and i can’t make sense of it all. it allows me to specify an object and script, but apparently not to trigger functions on that script.

am i supposed to put a script inside the button, or what? please give be a basic working example

Click on the + sign in the OnClick and a slot appears, if you have a script with a public function then put that script on a gameObject e.g. the button and then drag that gameObject onto the slot.

You can access that public function from the dropdown, just select MyScriptName → MyPublicFunctionName and when you click the button it calls that function.

Same is true if you Add and event trigger for, say PointerEnter just drag the object with the script onto the slot and select from the drop down.