Unity Development — Loading Scenes

Christopher Graf
3 min readJun 1, 2021

--

Scenes are the largest pieces to put together when developing your game in Unity. Working with separate scenes allows you to remain organized while being able to develop multiple levels or rooms at once. At some point though, they have to come together.

*Place picture of Title Screen Here*

With a bit of UI fun and design, we have made a Title Screen. It looks good and we hope it will entice others to play our game. Now we need to get them from the the Title Screen to a scene with some gameplay. Our first step, which is maybe the most important, is to make sure each scene you wish to be in your game is in your build settings.

You can find build settings at the top of Unity under File. Once you have those open, you’ll see a blank space up at top the says ‘Scenes in Build.’ At the bottom right of that section, you’ll also see a button that says ‘Add Open Scenes.” One at a time, you’re going to go into each scene you wish to add and press that button to add them.

Once you add them, you should also notice numbers to the right. You can change this order, if you wish, by clicking and dragging them up and down. These designated numbers will be important later.

We’re going to make a script that will allow us to go from one scene into another. While we’re at it, we’re also going to study how a UI Button works. In your starting scene create a Button. We don’t need to worry about what the text says or how big it is right now. In the Inspector you’ll see the Button component.

Towards the bottom, you’ll see ‘On Click ().’ This is where you will assign the method you want to be performed on the Button click. Let’s get back to that script now. Make a script, or use an existing UI or Game Manager script. In the namespaces at the top add ‘using UnityEngine.SceneManagement.’ You’ll need this to load the next scene.

Now make a public void method. In that method you are going to write ‘SceneManager.LoadScene().’ In the parenthesis, put the designated number of the scene you wish to load on the button click. You could also use quotation makes and the name of the scene, but that is genuinely slower.

Back to the Button Inspector. In the OnClick() section, hit the small ‘+’ and then drag whatever object is holding your script. This would most likely be the Canvas. Then use the drop down menu to find the name of the script and the public method. Run Unity now and push that button!

Look at that. New scene loaded. Now you have a huge new piece in making a truly special game. Keep up the great work.

--

--

No responses yet