Loading Scenes in Unity!!

Anurag Chawla
3 min readMay 10, 2021

In every game, there is a starting point — where player or user engage himself to understand the information about the game, its features/levels, controls etc.

Each of these respective section of game are made of Scenes and they are loaded based on when the user or player interact within the game.

In our Galaxy Shooter 2D- lets create a new scene — that is loaded first time when game starts and provides information about the game, who created it and how one can start the new game i.e, load another scene from the first scene.

File->New Scene

Click on File-> New Scene , it will create a new scene and save it say “Main_Menu”

Inside Canvas- Added Image with size of 512 X 512

Inside Canvas — added image MainMenu and updated it with name Title-Screen_Image and set the size of image as provided in width, height.

Canvas -Click Right -> Select UI and Add Elements as desired

Here in our case we will add the button and the text and update the text as below

Added Button with Text

And we can add the text and provide information who created the game set few properties like alignment needs wrap or overflow text horizontal or vertical.

Added Text and set properties

Once scene is created- one can add the scenes in Build when click on Add open Scenes or drag the scene from the Project tab from scene folder . The scene which are added under build settings assigned with an index number which one can refer in code to load the scene.

Click on -Add open scenes and it will add it

Now when we run the Game , it will load the Main_Menu Scene and when click on New Game, there will be on click event handler is called at run-time on button and it calls the MainMenu.LoadGame method.

On Click ()-> called MainMenu.LoadGame() method

This MainMenu script is added to the canvas and when it calls the LoadGame() method it loads the Scene having index -1, which open the Game Scene.

MainMenu Script -> which loads the Game Scene

Below shows when the MainMenu is selected , it open the Game Scene..

Game Scene loaded when click on New Game Scene

@GameDevHQ-Day …

--

--

Anurag Chawla

Emerging Technologies - Power Virtual Agents | AI Chatbots | Multi-Cloud & DevOps | UI Technologies - React , Angular | Gaming Technolgies - Unity, XR- AR/VR