Get current scene number
Hey. I was wondering if anyone could tell me how to get the current scene NUMBER. I know how to get the current scene. But what im trying to do is something like "int nextScene = currentScene + 1;" So that i can load the next scene no matter what scene it is. Could someone tell me how?
I think maybe Scene$$anonymous$$anager.GetActiveScene().buildIndex.
But note from the docs :
Returns the index of the scene in the Build Settings. Always returns -1 if the scene was loaded through an AssetBundle.
Answer by Alakanu · Feb 23, 2016 at 02:07 PM
Hey man, I was having the same struggle today. I think the solution is
sceneID = SceneManager.GetActiveScene().buildIndex;
That's very helpful. It appears that I'm still not fully understand Struct, which is why I'm searching for this.
Answer by hexagonius · Jan 16, 2016 at 12:58 PM
I think grabbing all scenes, writing them to a static array and then getting the index for the current scene of that array might be a good idea:
http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetAllScenes.html
Answer by x_mtd_x · Mar 18, 2017 at 05:46 PM
//in top of youre script
using UnityEngine.SceneManagement;
// gets the curent screen
Scene sceneLoaded=SceneManager.GetActiveScene();
// loads next level
SceneManager.LoadScene(sceneLoaded.buildIndex +1);
thats the new trick greethings Mathieu Dijkstra
Your answer
Follow this Question
Related Questions
Scene not loading on build but on editor it does. 0 Answers
Cannot interact with new scene 0 Answers
How do i create a scene variable? 3 Answers