CREATING THE MAIN MENU!

Abshire
6 min readDec 22, 2022

--

The first thing we need to do is go to file and selected new scene.

This new Scene is going to act as our main menu and we are going to create a start button where once we click on that it will take us to our game.

Lets first save our scene and name is Main Menu. Then we want to right click in the hierarchy and create a new UI Image and name it “Tittle_ Screen”. We are then going to add a source Image to this Object, so if you look in the sprites folder you will see a folder called UI and you will see a main Menu file so just drag that into the source Image inside the inspector of the Tittle_Screen. Go ahead and zero out the position for the X and the Y, that way it is centered. So far here is what we should have.

Next, Go ahead and also Preserve the Aspect Ration inside the inspector as well. Go ahead and change the width and height as well in the X and Y position to 512 and 512. You can also mess the with size inside the scene view to fit to the way you want it in the game view.

Next go to the main camera and set a background to pure black or whatever color you prefer to have the background look like you want. Don't forget to set the background in the inspector to solid Color and not Sky Box.

Now the next thing we want to is add that nice Space Back ground we use for our game and add that to the Hierarchy from our sprites folder.

The next thing we want to do is right click on the canvas and create a button to represent our start button and creating this we can add more text to it as well like “created by your name” if you wanted too. Anyways we create a new UI and select Button. ( =Which will be our “Start” Game button).

o we right click on canvas and go into UI and create a button on the button option “Button”. this is going to give us a button that ha a imagine and within in has some text. So move that in the scene view where you want in this cause I will have it to the right of the main menu. ( Also we can rename this inside the text to “NEW GAME”.

with Unity it it great because we can already click on the button in the game view when we play it but it of course will not do anything since we have to create a method for when we click that button he game starts. Also a fun fact about the button we can change colors and change the type of button and make it look however you want inside the inspector.

In the inspector you will see we have what's called an “ON Click Events” and what that is for is is what happens when we click the button, we can communicate that with our Scripts. What we need to do is drag our UI Manager and attach to the Canvas. However you will noticed from our work of code inside the UI Manager Script we have components attached to them but we don't need those so it makes sense for us to create a new C# Script for our main menu.

So Drag the Main Menu Script inside of the Canvas.

Also do not forget to do this step below changing the Ui SCALE Mode from constant pixel sizer to Scale with Screen size. Also dont forget to anchor with button as well.

So now lets open up our main Menu Script so we can create the logic for when we hit our “New Game” Button our game will start.

So when we call the load game method we need to access the scene Manager we need to load the game scene. so in order to do this we have to work with our build setting and apply both scenes to the settings. so we go into file, build settings, and we want to make sure the main menu us the first scene. so our game scene we will delete and add the main menu then we we can drag the game scene directly so we have 0 for the main menu and 1 for the game scene. once that is done we can close that out and go back into our Script for the Main Menu.

Now we can add this and then continue with our method.

Now we call this from the UI, this is where the “ON CLICK” comes back into play.

So when save this and play our game we can now hit the new game button and it will take us straight to our game.

Now the problem is when we die we cant restart, and the reason for that is because inside of our Game Manager we need to adjust our 0 inside our SceneManager to 1.

So we should be good now, but the last thing we are going to do is create some credits where whoever plays this game knows who made it. So for this I will be using my own name and for anyone else use your name.

This is just another simple step of right clicking on the canvas and creating a new UI text.

So with the new Object I just named it “ Created_By_Text, but you can name it whatever you want.

Also remember you can adjust the color and the position where ever you like as well.

Now we have our results !

--

--

Abshire

Just a Game Developer who is not afraid to push boundaries.