Loading Scenes in Unity: Making a Main Menu (Game Dev Day 23)

Jack Leavey
3 min readSep 8, 2021

--

In order to understand how to make a separate menu, we need to identify how a video game works.

Every “level” you play that is separated by a loading screen of some sort is a Scene.

The main menu is also it’s own Scene.

So in order to make a Main Menu for our game, we need to create a new Scene.

Make a new Scene and place it in the “Scenes” folder.

This new Scene (Main_Menu) is just going to contain the camera, directional light, and a some UI elements.

I changed the background to black and reused our in game Space background. This will all sit behind the menu options.

Make a new C# script (MainMenu) and attach it to the Canvas object so we can add some functionality to our main menu.

Now lets add a button. Buttons in Unity allow for rapid and trivial implementation of various outcomes.

Adding a button through the hierarchy.

Button’s automatically come with an attached text game object. We can use this to set what the button will show to the player (in our case I used “New Game”)

This button doesn’t do anything yet, but you can place it where you want it to be for the player.

You can also do a lot of fun things with buttons, like changing the color when you hover over it. Seriously, just spend 20 minutes screwing around with the components on your button it is extremely easy and fun to implement some rather interesting changes.

Let’s make our button actually start the game now.

What is starting our game? It’s just changing to the other scene. So we need to code out how to change scene, and then link it to pressing this button.

Inside the MainMenu script, the only thing we need is a public void to load the game.

This is all of the code for the entire main menu. It is very, very simple.

There is one more step in order for this to work.

The scenemanager can only find your scenes if they have been pushed to your build. It doesn’t mean you have to actually build your game.

Just click “Add open Scenes” option. Make sure you do this for both scenes.

With that, lets look at our button’s “On Click” component.

Unity has a built in Load function for buttons. Make sure you use it from the dropdown.

Now the main menu works, but you can always spice it up with some Images or credits, etc.

Simple Main Menu

--

--

Jack Leavey
Jack Leavey

Written by Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!

No responses yet