- Home /
              This question was 
             closed Jan 05, 2021 at 02:40 PM by 
             MustiKe for the following reason: 
             
 
            The question is answered, right answer was accepted
 
               Question by 
               MustiKe · Jun 23, 2020 at 07:25 PM · 
                c#playerprefssaveload  
              
 
              PlayerPrefs Script Problem
I made this code for highscore but this code only works when I close and open game How to make get value every time? (sry for bad english) Here is my code:
 public Text highscoreText;
 public static int highScore;
 void Awake()
 {
     highScore = PlayerPrefs.GetInt("highScore");
 }
 void Start()
 {
    highscoreText = GetComponent<Text>();
    highscoreText.text = highScore.ToString();
 }
 void Update()
 {
     if(Score.score > highScore)
     {
         highScore = Score.score;
         PlayerPrefs.SetInt("highScore", highScore);
     }
     
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by AyanRoy · Jun 23, 2020 at 08:45 PM
You need to update the highscore every frame. So call it from- Update function.
  public Text highscoreText;
  public static int highScore;
  void Awake()
  {
      highScore = PlayerPrefs.GetInt("highScore");
  }
  void Start()
  {
     highscoreText = GetComponent<Text>();
     highscoreText.text = highScore.ToString();
  }
  void Update()
  {
      if(Score.score > highScore)
      {
          highScore = Score.score;
          PlayerPrefs.SetInt("highScore", highScore);
          // updating highscore text every frame
          highscoreText.text = highScore.ToString();
      }
      
  }
Follow this Question
Related Questions
PlayerPrefs issue 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
onapplicationquit() function is not working with unity 4.6.3 (android) 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                