- Home /
 
 
               Question by 
               Hex2013 · Nov 28, 2014 at 10:16 AM · 
                playerprefshighscorecurrent  
              
 
              update highscore if current is higher than previous score
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;
   }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Where am I going wrong with these scripts? 1 Answer
Playerprefs not work!? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do you save timer with PlayerPrefs? 1 Answer
Making a hunger script 1 Answer