Highscore not showing up
Hello.
Idk why but my highscore script stopped working all of a sudden. I've got it set up like this: In my PlayerMotor script which is attached to the player I've got this in my onDeath function:
public void OnDeath()
{
isDead = true;
if(PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
deathMenu.ToggleEndMenu (score);
}
Which is casted when the player dies, it also displays a death menu i created where the highscore should be displayed.
So in my DeathMenu script i've got:
public Text highscoreText;
public void ToggleEndMenu (float score)
{
highscoreText.text = ((int)PlayerPrefs.GetFloat ("HighScore")).ToString();
isShown = true;
}
And i've got a text layer attached to the highscoreText in the inspector window.
DeathMenu and PlayerMotor are two different scripts. The normal score works perfecly fine.
So what could be the problem?
Can you elaborate? What doesn't work? Do you get an error? Is the wrong score displayed? Is no text displayed at all?
Your highscore should show up every time you die and it's not. It says "0" all the time for some reason. No errors.
In the editor the highscore just says "????" so it is doing something. It's displaying it as 0 tho. So it's either not being saved properly or it's not loading it properly. I really dont know, i'm new to program$$anonymous$$g.
Answer by LiloE · Mar 06, 2017 at 08:17 AM
Got it!
As usual with hard-coded strings, there's a typo. You have "Highscore" in some places and "HighScore" in others. It is always better to use a constant string and call it from anywhere instead of duplicating the string itself.
Your answer
Follow this Question
Related Questions
Il will start a script while i press a Button 1 Answer
How should I use the `FreeLookCam` script located in the standard assets folder 0 Answers
[C#]How to save a list of items to use in another script and it's not a player prefs type of list? 0 Answers
How to automatically generate a new int with a specific name? 1 Answer
Can someone please help me find out what wrong with my code. 1 Answer