- Home /
Saving And Loading A Float
Hello
Im trying to save and load my exp heres my script
var exp : float;
function Update () { AddjustExp(0); }
function AddjustExp(adj) { exp += adj; }
how can i make it so if i press a gui button in the top middle of the screen it will save my exp and when i load another level it loads my exp.
Thanks
Answer by Bunny83 · Apr 19, 2011 at 03:11 PM
If you want to save the value even across multiple game sessions use PlayerPrefs.
To save your "exp":
PlayerPrefs.SetFloat("currentXP",exp);
To load it:
exp = PlayerPrefs.GetFloat("currentXP",0);
The "0" at the end is the default value that is returned if it hasn't been saved yet. You can use any name you like to save values but it should be something you can remember ;)
Answer by Aldwoni_legacy · Apr 19, 2011 at 12:54 PM
// Make this game object and all its transform children
// survive when loading a new scene.
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
Right, for manager scripts that should survive the whole game that's the right way.
Your answer
Follow this Question
Related Questions
Application load advanced loading NO EXPERIENCE 2 Answers
How can I save the player's progress in-game? 1 Answer
Score system Level Load 1 Answer
[C#]Persistent Saving and Loading 1 Answer
checkpoint level please 2 Answers