- Home /
This question was
closed Oct 23, 2014 at 05:35 AM by
robertbu for the following reason:
Duplicate Question
Question by
TheBigBang · Oct 23, 2014 at 05:35 AM ·
c#guiplayerprefsscore
Highscore GUI not working properly help
I've manage to set and show a score after the player game is over, only thing wrong is when i ever beat the highest score, it doesn't show "New Highscore" it shows "Score:(Number of points earn during the game)". I want it to display New Highscore whenever the player beats their highscore, if you can help me with this thank you!
public GUIText scoreText;
int score;
int highScore;
bool newHighScore;
void Start ()
{
score = PlayerPrefs.GetInt ("Score");
if (!PlayerPrefs.HasKey("HighScore")) {
PlayerPrefs.SetInt("HighScore", score);
newHighScore = true;
highScore = score;
}
else {
highScore = PlayerPrefs.GetInt("HighScore");
if (score > highScore) {
newHighScore = true;
PlayerPrefs.SetInt("HighScore", score);
highScore = score;
}
else
newHighScore = false;
}
}
public void AddScore (int newScoreValue)
{
score += newScoreValue;
UpdateScore ();
}
void UpdateScore ()
{
scoreText.text = "Score: " + score;
}
if (playerLives == 0 && player == null)
{
GameOver();
if (newHighScore)
GUI.Label (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 10, 500, 100), "New High Score: " + score, "label");
else
GUI.Label (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 10, 500, 100), "SCORE: " + score, "label");
}
Comment