Hi everyone, I seem to be having an awful lot of trouble with player prefs the last few days. I have similar code to this in each of my levels for when the level ends:
##playerScript in my first level##
if(healthSlider.value <= 0)
{
if (PlayerPrefs.GetInt("forestRushHighScore", GUICounters.highestScore) < GUICounters.score)
{
GUICounters.highestScore = GUICounters.score;
PlayerPrefs.SetInt("forestRushHighScore", GUICounters.highestScore);
}
}
I have 8 levels, each one has a different key corresponding to that levels highscore. I also have a button on my main menu that I want to display the high scores for each level. The problem is, if I play one level, beat the high score and then check my highscores from the main menu, each level has the same high score as the level I just beat. I don’t know why, I’m using each unique key.
##my High Score script attached to the camera##
void Update ()
{
forestRush.text = “” + PlayerPrefs.GetInt(“forestRushHighScore”, GUICounters.highestScore);
catchEm.text = “” + PlayerPrefs.GetInt(“catchEmHighScore”, GUICounters.highestScore);
colorCoded.text = “” + PlayerPrefs.GetInt(“colorCodedHighScore”, GUICounters.highestScore);
defence.text = “” + PlayerPrefs.GetInt(“defenceHighScore”, GUICounters.highestScore);
target.text = “” + PlayerPrefs.GetInt(“targetHighScore”, GUICounters.highestScore);
flight.text = “” + PlayerPrefs.GetInt(“flightHighScore”, GUICounters.highestScore);
maze.text = “” + PlayerPrefs.GetInt(“mazeHighScore”, GUICounters.highestScore);
jumpRunner.text = “” + PlayerPrefs.GetInt(“jumpRunnerHighScore”, GUICounters.highestScore);
}
If anyone could point out something I’m doing wrong, i’d appreciate it, it’s the final thing I have to do before I’m finished my game.