- Home /
Save Player Health and stats
I am making a game where you get into random encounters and are moved to another scene where a turned based battle takes place. I need to save my players health for when he moves back into the world scene and then load it again once he re-enters the battle scene. I'm pretty new to javascript so please try to bear with me. Thanks in advance.
Answer by BiG · Apr 23, 2012 at 06:50 PM
You can use PlayerPrefs!
PlayerPrefs.SetInt("Health", player_health); //Stores the health variable
player_health = PlayerPrefs.GetInt("Health"); //Retrieves the health variable
Another example here.
Really? I wouldn't thought PlayerPrefs is the appropriate tool for save information. $$anonymous$$ore for things like remembering your graphic , sound , etc options.
It's the appropriate tool. He has to remember informations between a scene transition.
And what happens when he want to store the inventory of character, what missions he completed, etc in the future?
He needs to effectively do a game save. I just don't think PlayerRefs is the appropriate approach to this. On Windows its stored in the Registry which gives some indication of the purpose of this.
Saving it as a file. X$$anonymous$$L is often a good choice as its human readable and the there is some reference script:
http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_X$$anonymous$$L
That one actually also includes a save menu.
There is a good thread on the topic here:
http://answers.unity3d.com/questions/8480/how-to-scrip-a-saveload-game-option.html
If its really as simple as just a few stats then it is certainly cracking a nut with a sledgehammer and PlayerPrefs would do. But as soon as you need something more than just value pairs and require structure you need to write to a file.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Save data from one scene to another? 0 Answers
Retrieving basic Strings and Ints from XML Files (JS) 0 Answers
Damage/Healing over time 1 Answer
Saving/Loading Problems 1 Answer