DEV Community

Cover image for Managing HighScore with Unity's PlayerPrefs
Game Dev 4K
Game Dev 4K

Posted on

2 2

Managing HighScore with Unity's PlayerPrefs

In the last couple of days, I added a way to save the high-score in my game using Unity's PlayerPrefs API.

Also, I improved the end screen of the game.

PlayerPrefs Usage

Using the PlayerPrefs API is very simple. Here's my high-score saving logic looks like:

private bool SaveHighScore(int newScore)
{
    int highScore = PlayerPrefs.GetInt("HighScore", 0);
    bool gotNewHighScore = newScore > highScore;

    if (gotNewHighScore)
    {
        PlayerPrefs.SetInt("HighScore", newScore);
        PlayerPrefs.Save();
    }

    return gotNewHighScore;
}

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay