Creating a Main Menu in Unity

When playing games, the Main Menu is an after thought. As the player, you really don’t think about it because every game has one. It is standard. You would be pretty surprised if you clicked to open a game and instantly the game started. This article will talk about how to create a Main Menu with an interactive button that starts a new game.

The Main Menu is going to be a completely NEW SCENE. We are going to be adding an UI Image Element and in the Image Element we will add the Title Image. With this addition a Canvas and EventSystem is created in the Hierarchy.

In the Canvas, we are going to be adding a Button. Adding the Button, comes with a button image and a text component. The text component allows you to customize what text in the Button will read, font color and style.

The Button Element has customizable features that not only allows the button to be interactive, which is what the EventSystem handles, but you can customize what happens when the button is clicked, highlighted, pressed by changing colors, sprite images and/or animations.

The button also has the capability to execute a function when it is clicked. This is key, because we can tell the program what scene or level we want to load when the New Game button is click. This calls for a MainMenu script to be created and attached to the Canvas.

In the MainMenu script will need access to the UnityEngine.SceneManagement library, so we can access the Scene Manager. We now just need to create a public method of LoadGame and we will load the scene of the first level.

We will need to add the Main_Menu scene to our Build. In Build Settings, click on the “Add Open Scenes” to add it and we will have to rearrange it, so the Main_Menu is Scene 0 and the Game Scene is 1. You can easily to do this by clicking and dragging the Scenes in the Scenes In Build box.

Let’s revisit the On Click feature of the Button UI Element. First, we need to add the GameObject that has the MainMenu script which is the Canvas (red arrow). Once the On Click has access to the MainMenu script via the Canvas, we can call any of the methods on the script as long as the method is public. Now, when the Button is clicked, it will executes the LoadGame function that loads the game scene.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kubernetes 1.18.0 is out: Now What?

Dev Log: March 2022

Learn Python With Me!

Part 5 — Pagination, ordination and filters in RESTful APIs

Regexes are Hard

How to get rid of the “Public key cannot be exposed” error

CS371p Fall 2020: Nathan Eisenberg

Scala vs Kotlin: Practical Considerations for the Pragmatic Programmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan McCoach

Ryan McCoach

More from Medium

Timeline in Unity 2020

3D Level Design: Adding Emissions to Texture Maps

Using Cookies to Create Realistic Lighting

Game Dev Blog — Spawning Objects in Unity without the Clutter