Saving Highscore Upon Closing of App

This is a question I knew I’d eventually get to, and it’s a little deeper than it initially seems.

I can open my app and play as many games as I want and the highest score will be saved (I’ve attached the script if anybody would like to use it). But when I close the app permanently and re-open, the game does not display the high score I previously got. I understand why this is happening.

void Start () {
        if (highscore < 1){
        highscore = 0;
        }
    }
void Update () {
if (score > highscore)
            {
                highscore = score;
            }
}

My question is, how can I allocate a space on the phone to save that highscore permanently, whether the app is running or not - and to reload that highscore when the application is started.

Building upon that, if I create a system in my game where the game points can be used to purchase items, how could I save the variables that go along with that? If I want to eventually update my game once it’s on the store, I want those purchases to remain and the previous score/highscore to be there.

Thank you for the help.

Hello,
If i get your question right then you can try to save data into some kind of database (MySql or something like that) or through the webpage using WWWForm.

Try saving highscores in OnApplicationQuit() method.
And load in Awake() method.

void OnApplicationQuit()
{
    SavePlayerProgress();
}

void Awake()
{
    LoadPlayerProgress();
}
1 Like

Just to clear this up, variables dont get saved across app executions. That means, if you restart your app, all allocated memory of the old will be deleted and the freshly started app will get a new chunk of memory. Its not persistent!

To save data localy on the phone, use “PlayerPrefs”:

1 Like