Hi,
I'm trying my first PlayerPrefs high score system. I need to save the best score and time so I can have them display on the results screen and the high score screen. I'm using the solution from the example below as my base script:
http://answers.unity3d.com/questions/20773/how-do-i-make-a-highscores-board.html
This is what I currently have:
using UnityEngine;
using System.Collections;
public class HighScoreS1 : MonoBehaviour {
int newScore;
int newTime;
int oldScore;
int oldTime;
void AddScore(int score, int time){
newScore = score;
newTime = time;
for(i = 0; i < 10; i++){
if(PlayerPrefs.HasKey(i + "HScore")){
if(PlayerPrefs.GetInt(i + "HScore") < newScore){
//new score is higher than the stored score
oldScore = PlayerPrefs.GetInt(i + "HScore");
oldTime = PlayerPrefs.GetInt(i + "HScoreTime");
PlayerPrefs.SetInt(i + "HScore",newScore);
PlayerPrefs.SetInt(i + "HScoreTime",newTime);
newScore = oldScore;
newTime = oldTime;
}
} else{
PlayerPrefs.SetInt(i + "HScore",newScore);
PlayerPrefs.SetInt(i + "HScoreTime",newTime);
newScore = 0;
newTime = 0;
}
}
}
}
Any help is appreciated. Thanks.
↧