Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

update highscore if current is higher than previous score

$
0
0
in the script below, the highscore doesn't update at the start, if you have any help it will be appreciated. #pragma strict var High : int; function Start () { High = PlayerPrefs.GetInt("Highscore", 0); // again, second parameter is default if not found yet. guiText.text = "Highscore:" + High.ToString(); } the script that manages the score is this #pragma strict var Counter : int = 0; function addscore () { Counter += 1; } function Update () { Debug.Log("updated Guitext.text"); guiText.text = "Score:" + Counter.ToString(); } function endlevel (){ var oldHighscore : int = PlayerPrefs.GetInt("Highscore", 0); // second parameter is for default value if not found in player prefs. if (Counter > oldHighscore) { PlayerPrefs.SetInt("Highscore", Counter); // if the current score(counter) is greater than the old highscore, then you have beaten it. PlayerPrefs.Save(); // After setting, save/commit the new value(s). } guiText.text = "Score:0"; Counter = 0; }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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