Loading Scenes in Unity
Loading Scenes in Unity: Today were gonna talk about loading scenes in Unity. For starters lets begin by laying the foundation for Loading a Scene first. The first thing were gonna do is how do we establish restarting our game, first you must go into your hierarchy right click and go down to UI and select text. Now were gonna to the Inspector and rename UI text to Restart_text. Now in the inspector Text script lets type Press the “R” key to restart the level. The following step were gonna adjust the color in the color box to white in our text script. Now lets position our text at bottom in our game scene. The next step were gonna adjust the Font size to 28 in the inspector. Now your gonna notice your game scene that the Text Press the “R” key to Restart is being cut off. How do we fix that, well for starters you going to go over to vertical overflow in the inspector and change it from Truncate to Wrap so it fit all your text in the box. The only thing left for us is to resize the text box. The following step your gonna want to anchor this to the center bottom. Now with all that done how do we get our core mechanics of making the game restart and have a player disappear at same time, ill show you. All we need to do to load a new scene is just use SceneManager.LoadScene. One caveat, it’s part of a namespace called “SceneManagement” as you can see at the left. We’re going to have to insert that namespace into our script if we want SceneManager.LoadScene to work. Just type this at the top with the rest of the namespaces and we’ll have all the scene loading tools available to us. As you see can see below.
Now down below we can see our code for loading our scene we want to load.
Now that’s how we load a scene in Unity stay tune for more!