Hi. I have two different scripts in the game, one for the countdown time (Timer) and one for the score (Score). And my point is to set a new HighScore when the time is up. However, the highscore doesn’t seem to be working when I call it on debug.log, it always stays as 0. What am I doing wrong?
Here is part of the Score script :
static var score : int = 00;
static var highscore : int = 00;
static var highScoreKey = "HighScore";
function Start () {
highscore = PlayerPrefs.GetInt(highScoreKey,0);
}
function SetNewHighScore () {
if (Timer.seconds==0) {
if (score > highscore) {
PlayerPrefs.SetInt(highScoreKey, score);
PlayerPrefs.Save();
}
}
}
And here is part of the Timer script where I call the saved data:
function OnGUI () {
textTime = String.Format("{00:00}", seconds);
GUI.skin = theTimerSkin;
GUI.Label (new Rect (Screen.width/2,18,100,100), textTime);
if(seconds <= 0) {
seconds=0;
**Debug.Log(Score.highscore);**
}
}