Quantcast
Channel: Answers for "C# PlayerPrefs not Work"
Viewing all articles
Browse latest Browse all 4

Answer by YoungDeveloper

$
0
0
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

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>