1 Restart Scene multiple levels. Is this possible? - C# -
I have multiple levels in my game but have hit a wall when it comes to the restart side of things. I've done my research but can't seem to find a solution. Is there any way that I can have 1 "Game Over" screen, but when i click "Try again" it takes me back to the previous scene. Right now i have it so the 1st level "Game Over" screen takes me back to level 1 when i hit "Try Again" but then on level 2, when i click "Try Again" it takes me back to level 1, which is not what i want. Is there a way to go about this, like checking which level was the last one or something. I'm not an experienced coder so go easy. ;)
(Everything so far is in C# and i'd like to keep it that way please) :)
Thank You.
Answer by The_tubby1 · Mar 29, 2016 at 06:00 PM
The only way to accomplish this that I have found is to make multiple game over scenes even if they look the same.
Then position them in the build index underneath each level. So "level 1" is above "Level1GameOverScene" and "Level 2" is above "Level2GameOverScene" and so on.
Then add the script that says SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex -1);
onto The "Try again" text for example in your GameOver scene.
And attach another script onto the thing that causes the game to be over that says - SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
This way the scenes are relying working with each other as long as they are positioned correctly in the build index. This is the only way I can think of that is easy but I can almost guarantee that someone experienced can find a much easier way using code I've never even heard of.
I hope this helps others in my situation but if not, good luck finding a solution to your problem. :)