Work with UI elements

Hello, I am very new in Unity. I already know javascript.

I am currently developing main menu using Canvas and UI.

The question is how i should work with them?

  1. I need to load next scene on Start button click
  2. I need to quit game on Exit button click
  3. I need to show other UI elements on options button click

No need to show all functions, i just dont get how to get those buttons in script and work with them, like onClick event.

Thank you.

So as I understood you only need the way to get your click in code, that can be done if few ways:

  1. From inspector OnClick. THERE is Unity’s tutorial on that case.

  2. From code. I’ve shown 3 different approach examples HERE. As you use JavaScript I’ll give you few links, to cope with my C# code examples, as well:

Button.onClick - approach #3 in my example (works for buttons only)

OnPointerDown - approach #2 in my example (most versatile and rich)

OnMouseDown - approach #1 in my example (I’d strongly recommend AGAINST using this one for UI, that was just what TS used)

Button - here you can find other OnSomething functions examples

There are the other ways as well, like detecting mouse click and locating it on screen and locating UI in that point, but most likely you won’t ever need those.