I use PlayerPref.SetString to save the actual state of the game. Put it in OnApplicationQuit() and your game will be saved when you quit your app.
I Build 2 strings that i save this way. One contains the world information and one the specific game information like points, level task… And when the game gets load we parse the string back.
For complex game worlds that are dynamic created it would be good to create the world by an key. This way you only have to save the key and not every GameObject to rebuild the Gameworld.
We offer an resume Button if the game was not finished and Load it then with PlayerPref.GetString. So the Player can pause the game to if he wants to take a break and is also able to resume the game after a phone call.
Just wondering, how do you use this OnApplicationQuit function? Do you have to put it in a script that sits in every scene that the player might quit from?
P.
You could create an empty gameobject that never gets destroyed, and place it in the beginning of your game. (like scene 0). Then just attach the OnApplicationQuit() script.
Oh yeah, that makes sense! Thanks!
Hey one other question, is there any way of testing this inside unity? I’m guessing you would have to build it to see if it works.
Nope…PlayerPrefs work the same in the editor as in a build, and as for OnApplicationQuit, the docs (remember those? ) say, “In the editor this is called when the user stops playmode.”