how to save score to variable for ever.

Hello, so I have a new problem on my way of developing a game :slight_smile:
Ok so the thing is that.
I save current score to variable highscore and then meanwhile it saves and shows the highswcore but when i stop play it and re start it in Unity emulator the highscore is empty. And it does not shows it.
Any help? the code is this:
i is counter for current score.
public int highscore;

void GameOver()
	{

		if (i > highscore) {
			GUIText highScoreObject = GameObject.Find ("HighScoreObject").GetComponent<GUIText> ();
			highScoreObject.text = "Highscore: " + i.ToString ();
			highscore=i;
		}

	}

Use the PlayerPrefs class to save and retrieve your highscore. You are losing the highscore variable value when you stop and start your project.

PlayerPrefs

PlayerPrefs.SetInt

PlayerPrefs.GetInt

example:

void GameOver()
    {
 
       if (i > highscore) {
         GUIText highScoreObject = GameObject.Find ("HighScoreObject").GetComponent<GUIText> ();
         highScoreObject.text = "Highscore: " + i.ToString ();
         highscore=i;
         PlayerPrefs.SetInt("highscore", highscore); // highscore in quotes is the look up, the highscore not in quotes is your variable with the data, this will be associated with "highscore" in teh PlayerPrefs, the lookup can be whatever string value you want, but you must pull it with the same "name".
         PlayerPrefs.Save();
       }
 
    }