OnApplicationQuit
So. I've read the OnApplicationQuit() thing in the Docs around 50 times now. And i still have no clue how to Save my WHOLE game state. How would i go About saving a virtual pet game, I have Items you can Buy, Incemental systems and a simple day and night cycle. O Also read about Player Prefs but how would i go about it. I Really tried like a Gazillion times and it didn't work. And once i've saved i'd like it to load it automaticly every time i run the game. I don't have any Scripts to this, i heard something about Serialization. I need explainations ._. (Working in Unity 5.4b)
Answer by Rob2309 · Apr 07, 2016 at 06:27 PM
First of all, to be able to save your gamestate, you should begin by thinking about exactly what variables you have to save... Then you could write some wrapper classes that hold these values. You can then, when exiting the application save all those objects via serialization (basically writing an object as a stream of bytes, read more about this yourself please :D). To load all this you could add a gameobject to your startup scene that reads the created files back in in its start method... Those are only very general tips I can give you, but you have to specialize this basic system for your project yourself, as I don't know what exactly you are trying to save...
You sir just made my work so much easier. This helps a LOT. I'll learn up on Serialization then and Save Variables. As I'm making a Virtual Pet/Incremental game the main variables would be Health of the Pet, item and upgrade counts and such. Allright. Thanks, Have some points
Answer by b1gry4n · Apr 07, 2016 at 10:39 PM
http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Save examples:
PlayerPrefs.SetString("petName","Bleackk");
PlayerPrefs.SetFloat("petHealth",25);
PlayerPrefs.SetInt("upgradeLevel",3);
Load examples:
string tempPetName = PlayerPrefs.GetString("petName");
float tempPetHealth = PlayerPrefs.GetFloat("petHealth");
int tempUpgrade = PlayerPrefs.GetInt("upgradeLevel");
assign the temp values to whatever you want.
This is also very helpfull. I'm greatfull :). Have some Points :3
Your answer
Follow this Question
Related Questions
Help offline progression, works on windows but not on Android. 0 Answers
Save game - Tile based game 0 Answers
Loading live data to Unity from Processing 0 Answers
I can't figure out why my score doesn't save/increase 0 Answers
Save/Load Player System 0 Answers