You should not load or save anything in the update, as it runs every frame.
private void Start(){
if(PlayerPrefs.HasKey("Gold")){
Debug.Log("we have gold, loading..");
load();
Debug.Log("Gold:"+gold);
}
else{
Debug.Log("we dont have gold, adding 1 and saving.");
gold++;
save();
}
}
private void save(){
PlayerPrefs.SetInt("Gold", gold);
}
private void load(){
gold = PlayerPrefs.GetInt("Gold", 0); //gold will be 0 if key not found
}
Use [DeleteAll][1] to clear saved data on your local drive.
[1]: http://docs.unity3d.com/ScriptReference/PlayerPrefs.DeleteAll.html
↧