- Home /
Scoring System
Hey everybody so i tried a high score system for my game but im running into a few issues with it which i need help on. Sorry i'm a beginner and still learning how to make a decent high score system.
Issue #1 : The score is displayed, but the "Best Score" is always 0 is there anyway to make best score show the previous highest score in the game? Pic
Issue #2 : So in my game the score system is not displayed in the beginning , but after the game ends it does not turn on. Is there anyway to display the score after the game ends? In the Pic i provided i had to manually turn it on in the hierarchy/Inspector view. I want it to turn on after the player has lost all their lives.
Here is my scripts
void OnGUI()
{
if (playerLives == 0 && player == null)
{
scoreTxt.text = "Score: " + score.ToString ();
bestText.text = "Best: " + PlayerPrefs.GetInt ("Best");
scoreTxt.gameObject.SetActive (true);
bestText.gameObject.SetActive (true);
}
}
If you can help with my issue thank you!
Answer by C-Blunt · Dec 05, 2014 at 11:52 AM
Try getting your bestscore during Start()
For example...
private int bestScore;
Void Start () {
//get the current highscore.
bestScore = PlayerPrefs.GetInt ("Best");
}
// then modify the end to something like...
if (playerLives == 0 && player == null)
if (score>bestScore) {
//set the new highscore
bestScore = score;
//save the new highscore.
PlayerPrefs.SetInt("Best",bestScore);
}
{
scoreTxt.text = "Score: " + score.ToString ();
bestText.text = "Best: " + PlayerPrefs.GetInt ("Best");
scoreTxt.gameObject.SetActive (true);
bestText.gameObject.SetActive (true);
}
}
you may wish to check that as it hasn't been tested but should point you in the right direction.
In terms of displaying your score during gameplay, have a look at the new 4.6 UI tutorials.
Sorry for the late reply i was bust over the few days thanks for the response! But a couple of things it works, but it only display once unless you beat your highest score. For ex. if had a score of 60 and retry the game and had a score of 10 it will not show my current score nor my best score. Is there any workaround to this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613173252im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
whats wrong with my high score code? 1 Answer
Highscore GUI not working properly help 0 Answers
Distribute terrain in zones 3 Answers
Why isn't my high score sticking? 2 Answers