- Home /
i need help making a multiple level game
ive been messing around an improving the roll a ball game that you can learn in the tutorial and I was wondering if there is a way to make it so once the player collects all the floating cubes it will reset the score and teleport it to the next level I'm trying to make 3 or more levels
Answer by oStaiko · Sep 15, 2018 at 03:26 AM
What you want is multiple scenes. A scene is what you build the game in; it can be a level, a menu screen, all sorts of things. If you want to make a new scene that is similar to your current one, hit Save Scene As and give it a name like "level 2". https://docs.unity3d.com/Manual/CreatingScenes.html
Now you want to change levels when certain conditions are met, this is also super easy. To have a near-instant scene change, type in:
SceneManager.LoadScene("Level2");
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
If you are going for super-basic, this is okay. But instant loading is pretty unappealing, so you'll want a delay on it, and some notification or confirmation. You can have a UI panel appear with some text saying "Congrats! Loading new level..." and then have the level change in 3 seconds or so, or when the player click a confirmation button.
Scenes may take a moment to get used to if you havent seen anything like it before. Everything in a scene is deleted and reset when changing and loading a new scene, so any changes to the level will be undone. All non-static and non-persistent variables/objects are also deleted. It is usually not needed for small projects (like this one) to remember things in-between stages, but this can be done by saving/loading data (not reccomended), or with persistent objects.
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
quick question where would I put that code
Scene$$anonymous$$anager.LoadScene("Level2");
Your answer
