Reputation: 265
In my game I have several levels, each one has 6 scenes, the scenes names are: Scene 1, Scene 2, Scene 3 ...etc...
When the player lose, the current scene should be restarted, so I used this code:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
I didn't use "(...)GetActiveScene().name);" because the scenes names are repeated on each level.
The problem I have is when the player lose in level2 (scene 6), the scene 6 of level1 is loaded instead of restarting scene 6 of level2. Do you know what's the problem in my code?
Upvotes: 0
Views: 263
Reputation: 90901
Maybe not an answer to why this happens in your specific case but two suggestions I would prefer:
Just a workaround but how about naming your scenes properly instead like e.g. Level1_Scene1
, Level2_Scene3
etc
so they are all uniquely identifiable using GetActiveScene().name
Alternatively you could also try using GetActiveScene().path
(which is allways unique) since LoadScene
takes
Name or path of the Scene to load.
Upvotes: 1