The highscore will work when I reload the scene, but when I close the app, the highscore variable won’t save and it will be set to zero. here is my code:
public static int highscore;
public static int score;// The player’s score.
public int value = 1;
Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
// Reset the score.
score = 0;
}
void Update (){
if (score > highscore) {
highscore = score;
}
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score + "
Highscore: " + highscore;
}
void Start () {
PlayerPrefs.GetInt ("highscore", 0);
}
void OnDestroy () {
PlayerPrefs.SetInt ("highscore", highscore);
}
}