How can record score in unity

Hi.
How can I do to be saved when the score of the game is rebooted.
When the user is off his game score will be recorded.
Recorded score will stand in place when the game opens.
How can I do??

Thanks

The easiest way to achieve that is by using PlayerPrefs:

Thanks @Dantus Can you give example

http://lmgtfy.com/?q=unity tutorial playerprefs

thanks by

It is not my intention to be unfriendly. It is okay if you don’t know where to start and that you may somehow not find PlayerPrefs. But with that, it is really trivial to find lots of examples.

1 Like

Best regards from me,here we are all on the same task,to make a good GAME!!!

Not really, some of us are here for self promotion of our own tutorial, assets, art ect. Some of us just like helping random strangers on the net.

maybe you are right,but y think dantus try to help…y am new in unity,and it looks ok for me,you have documentation,tutorials,forum where you can learn a lot…best wishes

This is the persistent data pattern I like to use in Unity3D:

using UnityEngine;
using System.Collections;

public class PersistentSettings
{
    const int DefaultHighScore = 10000;
    const string s_HighScore = "HighScore";
    public int HighScore
    {
        get
        {
            return PlayerPrefs.GetInt( s_HighScore, DefaultHighScore);
        }
        set
        {
            PlayerPrefs.SetInt( s_HighScore, value);
        }
    }
}

Whenever you want to set a high score at end of game, your code might look like:

if (Score > PersistentSettings.HighScore)
{
    PersistentSettings.HighScore = Score;
}

You can put any other settings you want in there, like sound on/off, etc.

1 Like

Altruism prevails! o/

on topic: player prefs is definitely the easiest way to save something as basic as a top score. Load it into the program when your game starts, save it after a completed round if it’s greater than the previous top.

Since we are back on topic its worth pointing out that player prefs is stored as plain text. On a PC my three year old daughter could hack into it and change the scores. Totally up to you how secure you want to make it.

On easy way to quickly stop amateur hackers would be to serialise the score using a binary formatter, and store the resulting string in player prefs (or a file). Not enough to stop a genuine hacker, but it will stump any amateurs.

hackers are only ruining it for themselves :stuck_out_tongue:

True. But it can be a hell of a pain if you later decide to use the same system for an online leader board.

Of course this all assumes your game is popular enough to attract people that want to take the time to fake high scores…