How to move to next scene using scene manager?
Hi everyone,
I am doing a tutorial that is using unity 4 and they are using this:
Applicaiton.LoadLevel(Appliaction.loadedLevel +1);
in order to move on to the next scene. I am using unity 5, and it is telling me to use scene manager since the previous method is now obsolete.
My question is, what is the new code to replace the one above? I can't seem to figure it out.
Thanks in advance.
Answer by jrodgersjr · Apr 24, 2017 at 05:01 PM
You can shorten the above with the following:
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex + 1);
Answer by corn · Feb 13, 2016 at 11:27 AM
Use SceneManager.GetActiveScene and Scene.buildIndex.
int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
if (SceneManager.sceneCount > nextSceneIndex)
{
SceneManager.LoadScene(nextSceneIndex);
}
Don't forget to include the SceneManagement module with using UnityEngine.SceneManagement;
Answer by yopunky · Oct 06, 2016 at 08:54 PM
To get the next scene in the build (not loaded in the Hierarchy) you need to use SceneManager.sceneCountInBuildSettings and not SceneManager.sceneCount.
int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
if (SceneManager.sceneCountInBuildSettings > nextSceneIndex)
{
SceneManager.LoadScene(nextSceneIndex);
}
Your answer
Follow this Question
Related Questions
When I load a scene a second time, some objects don't show up 0 Answers
multiple of same objects from DontDesroyOnLoad 0 Answers
Game crashes after button is clicked to load scene 0 Answers
How can I load a new scene without losing context of previous? 0 Answers
How do I trigger a function right after a additive scene ends? 0 Answers