A quick guide to loading scenes in Unity
Now the game is over what next? We need to provide a way for our players to start again. This is where scene management comes in.
Restarting a level can be as simple as loading the game scene. In order to load scenes however we need to make sure we import the correct library.
We are going to run logic that checks for when the “r” key is pressed (in the new input system). We only want the player to be able to use this action if the game is over so we will add this to our logic too.
Now we can load the scene a couple of different ways. First, we can do it by passing in a string “scene name” or using the scenes int reference.
We can find our scene int reference in our build settings. We can also arrange and add scenes here too.
I prefer to use a string to load a scene as we can ensure we will not have to change our scripts if they get moved around in our build settings.
And now we can see it in action.
That’s all for now.