Loading Scenes in Unity

How to Setup Scenes:

Mike LePonto
3 min readMar 9, 2024

Set scenes index up in the build settings.

Order the scenes in the index from first to last.

Note: You delete scenes by clicking on them and pressing the delete key on the keyboard. You add scenes by opening them in unity and then clicking the add open scene button in the build settings.

How to Load Scenes:

Code is required to load scenes.

You must add the SceneManagement Namespace

The SceneManager.LoadScene(SceneIndexNumber) command loads the scene given the index number or the number to the right of the scene name in the building settings menu as seen above.

This loads my main game scene where the player plays the game from the main menu.

How to initiate loading a scene:

To execute the load scene method you can initiate many ways.

Common ways are by player inputs or by buttons in the UI.

I created a New Game Button on the Main Menu to load the main game screen.

However, I also check for user input of the “R” key to restart the game and reload the main game scene once the player dies.

The Code:

The code for these functions use the principles discussed above.

Load the Game:

Note: Here I used the built in unity editor functions to tell the button to call the LoadGame() method

Open the button inspector.

Navigate to the On Click() component. Tell the component to access the Canvas Object, find the Main Menu Script and call the LoadGame() method.

Restart The Game:

Result:

Click the New Game button and start the game.

When the player dies press R to restart and reload the scene

--

--