How to load the last level when the game open again ?
Hello everyone ! I have a old question . How can i load the last level when i open game again ? Ex : Im playing at Scene/level 3 . I quit game and open it again . So , how can i do to open level 3 without play again level1 & 2 ? Please give me a simple example . Im very weak in writing code . For more help , Could you give me a Clip , picture for described easily . Thank you a lot ! :D
Answer by sumitb_mdi · Dec 18, 2016 at 10:46 AM
What you want is a persistent storage of how many levels are finished. Unity has a pretty useful persistent storage API which abstract out the underlying platform. This API is PlayerPrefs.
What you need to do is Set the Level Number as soon as you load the scene for that level. And when the game launches initially, you can read the last level played and directly load scene corresponding to that level.
PlayerPrefs.SetInt("LastPlayedLevel", 2); //Call this as the first thing when you load your scene for level 2
int currentLevel = PlayerPrefs.GetInt("LastPlayedLevel"); //Call this as the first thing when your game starts, and load the level corresponding to "currentLevel".
Your answer
![](https://koobas.hobune.stream/wayback/20220612102945im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
pause menu loads saved game quirky 0 Answers
how do i store highscore locally C# (SIMPLE) 3 Answers
PlayerPrefs help ! 1 Answer
how to randomly instantiate prefabs but each with it's own probability? 2 Answers