Creating A Main Menu Scene In Unity3D

Pete Thomasberger
4 min readJun 3, 2021

--

Objective: Create a Main Menu scene with a New Game button that will load the Game scene.

Step 1: In Unity, navigate to the File menu and click on New Scene. Select the Basic option and click Create. Once the scene is open, press CTRL-S to save the scene in the Scenes folder and call the scene Main_Menu.

Step 2: Drag a background image or skybox and drop it into the Scene view. Alternatively, a solid color can be used as well.

Step 3: Go to the File menu and select Build Settings…. Delete the Game scene from the Scenes In Build section and click the Add Open Scenes button. Then drag the Game scene back in under the Main_Menu scene. This will assign the Main_Menu scene a value of 0 and the Game scene a value of 1.

Step 4: Right-click in the Hierarchy window, go to UI, and select Button from the dropdown. This will create a Button GameObject within a Canvas GameObject, as well as creating a new EventSystem. Rename the Button GameObject to New_Game_Button.

Note: Images can also be added to the Title Screen within the Canvas boundaries. Just be sure to select the Scale With Screen Size setting in the Canvas Scaler component attached to the Canvas GameObject.

Step 5: Select the New_Game_Button GameObject in the Hierarchy window and adjust the button’s position within the canvas boundaries in the Scene view. Then, click the disclosure triangle on the New_Game_Button GameObject in the Hierarchy window and select the Text GameObject. The Text GameObject handles the visible text within the New_Game_Button GameObject. In the Text component in the Inspector window, replace the default text with New Game, and adjust the font settings as desired.

Step 6: In the Project window, create a New Folder within the Scripts folder and name it Main_Menu. This will hold all scripts pertaining to the Main Menu. Create a new C# Script within the Main_Menu folder and call the script MainMenu. Then attach the MainMenu script to the Canvas GameObject in the Hierarchy window and open the script.

Step 7: In the MainMenu script, add the SceneManagement library, and create a new public method called LoadGame(). Within the LoadGame() method, load scene 1 using the SceneManager and save the scene. When this method is called, the Game scene (which was reassigned a value of 1 in the Build Settings) will be loaded.

Note: Be sure to also update this change in the RestartLevel() method in the GameManager script.

Step 8: In Unity, select the New_Game_Button GameObject in the Hierarchy window. Within the Button component in the Inspector window, click the + button to add a function to the On Click () list. Drag the Canvas GameObject into the Object slot since the Canvas has the MainMenu script attached to it. From the dropdown on the right, select MainMenu and select the LoadGame() method. This will call the LoadGame() method from the MainMenu script and load the Game scene when the New_Game_Button is clicked.

Save the scene and press the play button. This will bring up the Main_Menu scene first and when the New Game button is clicked the game will start.

--

--

No responses yet