I am trying to save highscores for my motorcycle game. But when I close the app out of my iphone and reopen it once I score some points it overrites the highscore.This is only after I close the app completely. I am trying to display the player prefs after I get the value with a guitext.
function Start ()
{
I would say you do not really need to save in the Update. Since you are on iOS you can use:
or:
but make sure you read the bottom line of the page about the iOS not quitting.
Then you are getting the value on Start and again you do not need to check in Update, create a method to update the score value and at the same time check if bigger than the HiScore:
private var highScore:int;
private var score:int;
private var maxValue:int = 10000000;
function Start()
{
highScore = PlayerPrefs.GetInt("highscore");
highscoretext.text = highScore.ToString();
}
function AddScore(newScore:int)
{
if(newScore < 0)
{
Debug.LogError("Negative value?...Really?");
return;
}else if (newScore > maxScore)
{
Debug.LogError("That is a big score??!!");
return;
}
score += newScore;
if(score > highScore)
{
highScore = score;
highscoretext.text = highScore.ToString();
}
}
function OnApplicationPause(pauseStatus: boolean) // Or Quit
{
PlayerPrefs.SetInt("Highscore", high_score);
PlayerPrefs.Save();
}