I have tried to use a basic high score script, but it does not save…at all…
Everytime I restart a round and die, the high score remains at 0…
In this script, I reference another script Health.kills
int highScore = 0;
bool newHighScore;
// Use this for initialization
void Awake(){
Health.kills = 0;
Time.timeScale = 0.0f;
}
void Start ()
{
Health.kills = PlayerPrefs.GetInt ("Score");
if (!PlayerPrefs.HasKey ("HighScore")) {
PlayerPrefs.SetInt ("HighScore", Health.kills);
newHighScore = true;
highScore = Health.kills;
} else {
highScore = PlayerPrefs.GetInt ("HighScore");
if (Health.kills > highScore) {
newHighScore = true;
PlayerPrefs.SetInt ("HighScore", Health.kills);
highScore = Health.kills;
} else
newHighScore = false;
}
}
void Update () {
{
if (PlayerLives.lives <= 0) {
Time.timeScale = 0.0f;
guiText.fontSize = Screen.width / 10;
guiText.fontSize = Screen.height / 10;
guiText.text = "High Score: " + PlayerPrefs.GetInt ("HighScore"); // update the GUIText
}
else {
Time.timeScale = 1.0f;
}
}
}
}