You might want to look into [PlayerPrefs][1]
Here is an example,
int Highscore = 0;
void Start()
{
//loading highscore
Highscore = PlayerPrefs.GetInt("MyHighscore");
InvokeRepeating("CreateObstacle", 1f, 1.5f);
}
void CreateObstacle()
{
Instantiate(rings);
score++;
//saving highscore
Highscore = PlayerPrefs.SetInt("MyHighscore",score);
}
PlayerPrefs.SetInt may have a slight performance issue if called every frame ( especially on mobiles). So try to save at the end of the scene, on exit or at some checkpoint.
[1]: http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
↧