I'd like to save the player's high score using Unity's PlayerPrefs
API. This is the code I have so far:
public int coins;
public int score;
public int highscore;
public int points;
public Text pointsText;
public Text HighScore;
public Text Score;
public Text coinsText;
void start(){
highscore = PlayerPrefs.GetInt ("HighScore");
}
void Update () {
if(points > highscore){
highscore = points;
HighScore.text = ("HighScore: " + points);
PlayerPrefs.SetInt ("HighScore", highscore);
PlayerPrefs.Save ();
}
score = points;
pointsText.text = ("x " + points);
Score.text = ("Score " + points);
PlayerPrefs.SetInt ("Score", points);
coinsText.text = ("Coins " + points);
}
However, it does not work. Every time I restart the game, the high score is 0 again. How can I make this work?