Adding a Main Menu to our UI
Let’s create a new scene and name it MainMenu as shown above.
Let’s create our canvas and an image for our title screen logo.
Again, I’ll be using the assets provided by GameDevHQ, but you can use any image you like here.
We’ll go ahead and 0,0,0 the position, assign the sprite, set our width and height to match our native Image Size (shown at the bottom right of above gif in inspector window), and select “Preserve Aspect”.
We’ll set up some properties on our canvas as shown above.
We’ll add in our Nebula background and resize it to fit our screen.
Create the New_Game_button and rename it.
Go ahead and select a highlighted color for the New_Game_button.
Position the New Game button as desired in the scene view.
Let’s open our build settings and not only add this MainMenu scene, but reorder our scenes so that MainMenu is index 0.
Let’s create a new script called MainMenu and add it to our Canvas game object.
We’ll add our SceneManagement using statement and a LoadGame() method to, you guessed it, load our scene.
With our scenes newly reordered, our “Game” scene is index 1 and that is the value we will need to use.
The Unity editor makes it easy for us to connect our button to our LoadGame() method on the MainMenu script.
We select our button, add an “On Click ()” event, drag the canvas object into the field (MainMenu script lives on Canvas game object) and select the LoadGame() method from the function menu dropdowns.
That’s it, run the game and the Main Menu should load up and work correctly!
In the next article we will work on enemy explosions.