hi guys, its my first time doing player prefs, so please be gentle.
so basicly at the end of my game i display 2 ints, highscore and best streak, this works fine
what i would also like it to do is check the new score against a player pref highscore, if the new score is bigger it should update in player prefs,
so on my splash screen i have this
function Start () {
PlayerPrefs.SetInt ("HighScore",0);
PlayerPrefs.SetInt ("BestStreak",0);
PlayerPrefs.Save();
}
on my death screen i have this
function Start ()
{
if (PlayerPrefs.HasKey("HighScore")){
var bestScore =PlayerPrefs.GetInt ("HighScore");
if (holdScore.currentScore >= bestScore){
PlayerPrefs.SetInt ("HighScore", holdScore.currentScore);
}
}
if (PlayerPrefs.HasKey("BestStreak")){
var bestStreak =PlayerPrefs.GetInt ("BestStreak");
if (holdScore.bestStreakScore >= bestScore){
PlayerPrefs.SetInt ("HighScore", holdScore.bestStreakScore);
}
}
}
function OnGUI()
{
//Buttons
if (GUI.Button (Rect (Screen.width-64,Screen.height-64,64,64),"", contactIcon)) Application.OpenURL(DataCenter.contactURL);
if (GUI.Button (Rect (64,Screen.height-64,64,64),"", replayBtn)) Application.LoadLevel("Game");
if (GUI.Button (Rect (0,Screen.height-64,64,64),"", homeBtn)) Application.LoadLevel("menu");
//Score display
GUI.Label (Rect (Screen.width/2-128,128,256,64),String.Format("Score:"+"{0}",holdScore.currentScore),textStyle);
GUI.Label (Rect (Screen.width/2-128,160,256,64),String.Format("HighScore:"+"{0}",bestScore),textStyle);
GUI.Label (Rect (Screen.width/2-128,224,256,64),String.Format("Highest Streak:"+"{0}",bestStreak),textStyle);
GUI.Label (Rect (Screen.width/2-128,192,256,64),String.Format("Best Streak:"+"{0}",holdScore.bestStreakScore),textStyle);
if (GUI.Button (Rect (Screen.width/2-64,128+96+72,128,128),"", replayBtn)) Application.LoadLevel("Game");
}
My GUI stuff all displays, high score and best streak as zero, currens score and current streak all work fine, but it never updates to a new score, please guide me in the right direction, thanks guys