Help with my score and highscore script
For some reason with my code below if I get a score greater than my previous highscore it does not show as New highscore: X but just as highscore: X. Can anyone spot what's wrong?
public void GameOverScore()
{
if (Score > PlayerPrefs.GetInt("Highscore"))
{
PlayerPrefs.SetInt("Highscore", Score);
HighScoreScript.manager.newHighScore();
ScoreScript.manager.LatestScore();
}
if (Score <= PlayerPrefs.GetInt("Highscore"))
{
PlayerPrefs.SetInt("LatestScore", Score);
HighScoreScript.manager.highScore();
ScoreScript.manager.LatestScore();
}
}
That code links with this:
public void newHighScore()
{
HiScore.text = "New Highscore: " + PlayerPrefs.GetInt("Highscore").ToString();
}
public void highScore()
{
HiScore.text = "Highscore: " + PlayerPrefs.GetInt("Highscore").ToString();
}
Comment
Answer by gjf · Jan 14, 2016 at 01:19 PM
it's because it's setting the new text twice.
your initial check will set a new high score, but instead of using else
, you just test for it being equal/less every time too...
if you'd added some Debug.Log()
in your newHighScore()
& highScore()
methods then you'd see that both were being called...
Your answer
Follow this Question
Related Questions
Survival Shooter Error CS0120 1 Answer
Best server-side score storage service 0 Answers
How do switch scene with singleton pattern unity3d C# 2 Answers
Enemy Follow Player tutorial? 1 Answer
Grading system not working 1 Answer