- Home /
Question by
GodPlaysProductions · Jan 26, 2020 at 10:40 PM ·
scorescore systemhighscoresscoreboard
How to create a HighScore using playerprefs based on passed time?
Hello everyone! I am currently creating a game where the score is passed time. When the player dies a restart panel is shown and the timer no longer updates. But my highscore is not working and I don't know why.
void Start()
{
HS.text = PlayerPrefs.GetFloat("HighScore").ToString();
}
void Update()
{
if (restartPanel.activeInHierarchy == true)
{
if (timeLeft > PlayerPrefs.GetFloat("Highscore", 0))
{
PlayerPrefs.SetFloat("Highscore", timeLeft);
HS.text = timeLeft.ToString("0");
}
}
if (restartPanel.activeInHierarchy == false)
{
timeLeft += Time.deltaTime;
startText.text = (timeLeft).ToString("0");
}
}
Comment
Answer by DennisSchmidders · Jan 27, 2020 at 12:41 AM
In Start function you read High(S)core with a big S letter and in the update, you save it in High(s)core
so Read : HighScore and write : Highscore Because of not setting the big letter at "S" you write and read two different PlayerPrefs
Your answer
Follow this Question
Related Questions
Score not increasing after killing 1 enemy 2 Answers
Highscore with points and time 1 Answer