How to link UI Button to Script in Unity

Main menu button to start the Game

Tristan Engel
May 21, 2021
Main menu button in action

Main Menu UI Button

Let’s create a UI button on a main menu scene to load the game scene.
1. Create a UI Button
2. Create script with a public method to load the Game scene
3. Attach the script to the Canvas (of main menu scene)

Build Settings

File > Build Settings > Add required Scenes here by dragging from Project panel
Here you can check the buildIndex (number on the right) and the names of scene.

OnClick event of the Button

Here we can assign our method to load the game to the UI button click.
1. Drag the object with the script (Canvas) into the box
2. Select the script (MainMenu)
3. Select the method (LoadGame())

--

--

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.