Main Menu Scene

Objective: Apply knowledge of UI and Scene management to the Main Menu scene creation

Here we’re going to use what we learned before in order to create a Main Menu scene, similar to what we can find in every game we played!

First, let’s create a new scene: from the project view right click on Scene folder and proceed to create a new scene, then load it with a double click.

The scene name will be Main_Menu or something similar. The new scene will be empty of course. Let’s add the galaxy background as did before and proceed with UI creation.

Let’s start with an image. I’m using a sprite with the name of game.

As usual, set anchorage and central position and canvas rescaling. Then set the skybox of the camera to a good solid black colour.

Now, the purpose of the main menu scene would be to welcome the players and give them the possibility to start the game by pressing on a button. Buttons are another example of UI element easily creatable along with text and images. Let’s create one, give it a proper name (NewGameButton) and learn a bit more about it.

The button comes with a child text object, namely the text inside the button. We can change font and size as usual and set a value (for example New Game). It is also possible to change default, highlight and pressed colours, according to our needs. Adjust anchorage, size and position.

Here comes the juicy part: OnClick() method. As the name states, here we can design what is going to happen when the player clicks on the button.

Of course, we first have to code this behaviour, so let’s proceed with the creation of Script, MainMenuManager, and attach it to the canvas.

A simple public method with a call on the scene manager to load the level 1 scene. Since it is public, Unity editor can access it. If we add one behaviour (plus button) we are given the possibility to choose a gameobject, click on canvas. Then from the no function dropdown you can choose a component, MainMenuManager script, and then visible (public) methods: StartGame().

Yeah… but…

I mean… it’s ok to use the power of Unity editor, but I long to learn more, to answer many questions.

For example: what if I want something to happen on click, among several possibilities and want to choose that one according to some criteria?

In other words: is it possible to programmatically decide which method is run on click?

Yes, of course.

We modify the MainMenuManager script as follows.

There is a usual grab of the button, as child of the canvas and then a simple line in which we add a delegate to listener (many can be added). In other words the button waits, “listening” for a click event and when the click arrives it executes the command(s) we have added.

Hey! Noticed the nice Level 1 fading text? Check the GitHub Repo!

Let’s finish with this other info: if you go in File — Build Settings you will find a panel in which you can add all the scenes you want to include effectively in your game. You can then order them and the index on the right can be used in place of scene name when you want to load scenes.




A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams

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

Recommended from Medium

Guess the number with Python !

TeamFight Tactics — Class Synergy Guide

How to upgrade cmake in ubuntu

BLOC Architecture Explained

AI with Python — Supervised Learning: Classification

Migrate ASP.Net core from 5.0 to 6.0

Programming Paradigm — Onload Code

LeetCode Challenge — 6/16 Validate IP Address

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
Daniele Quero, PhD

Daniele Quero, PhD

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams

More from Medium

2D Light Flicker in Unity

Journal 146 — Unity Project Development, 2.5D Shooter

Creating enemy movement behavior

Damage VFX using Animated Sprites in Unity