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.

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();
    }

Can anyone spot what’s wrong?

put a debug.log entry into the newHighScore function & see if it is going to it.

When you get a new high score & it just show High score does it show the correct (new) value?

It seems to play both at the same time for some reason…

i think what is happening is that because you used 2 if statements it does the first one, goes to the new high score, then goes back & checks the next if statement & now the score equals the high score. Change the second if check to else if instead so it can only do one.

I heard that using else if is bad though ?
But it does work, thanks a lot man.
I can finally go sleep!:smile:

1 Like

wut? :eyes::face_with_spiral_eyes:

It was in a video, if I can find it I’ll link it.

Don’t ever watch videos from that person again.

3 Likes