- Home /
 
 
               Question by 
               Klousianic · Jul 29, 2014 at 05:58 PM · 
                playerprefsscorehighscore  
              
 
              Playerprefs not work!?
Hi everyone. I have a problem. I make a runner game and now I want to make a script that will show my current score. But when I play my game it doesn't show me my current score. It shows this "Score: 0" everytime. What did I do wrong?? Here my score script:
     function Start(){
     InvokeRepeating("EachSecond",1.0,1.0);
     }
      
     var score: int = 0;
     var addscore = 1;
     var score1 : GUIText;
     var bim : GameObject;
      
     function EachSecond()
     {
     score=score+addscore;
     }
     function Update()
     {
     score1.text = "Score: " + score;
     
     }
    
     function GameOver(){
         PlayerPrefs.SetInt("Score", score );
     }
 
               and here my final score script:
 #pragma strict
 
 private var score : int = 0;
 var scoreText : GUIText;
 
 function Start() {
 score = PlayerPrefs.GetInt("Score");
 }
 
 function Update () {
 scoreText.text = "Score: " + score;
 //GUI.Label(new Rect(Screen.width / 2 - 40,30 ,80 ,300), "Score: " + score);
 }
 
               Please help me and sorry for my bad english.
               Comment
              
 
               
              Does the score update correctly while the game is playing, at least?
How are you calling that GameOver function? If that doesn't get called, the SetInt call won't happen. 
$$anonymous$$ight be because you are missing a PlayerPrefs.Save() after SetInt.
Your answer