High score resets with score?
Hey everyone I have a simple game that I'm working on and there is a scoring system in place. I have it set up so once the timer hits "0" it changes scenes to the "Game Over" scene that has your score, highscore, and a retry button that goes back to the game. When I go from the game to the game over screen everything works as it should. And from the game over to game screen the score resets but so does the highscore. Any tips to make it so high score remains? The code is in both a score manage and game manager.
SCORE MANAGER
public class ScoreManager : MonoBehaviour
{
public static float score; // The player's score.
public static float highscore;
public Text highscoretext;
public Text Scoretext; // Reference to the Text component.
void Awake()
{
PlayerPrefs.GetFloat("HighScore");
highscore = PlayerPrefs.GetFloat("HighScore");
PlayerPrefs.GetFloat("scorepref");
score = PlayerPrefs.GetFloat("scorepref");
}
void Update()
{
if (score > highscore)
{
highscore = score;
PlayerPrefs.SetFloat("HighScore", score);
}
PlayerPrefs.SetFloat("scorepref", score);
Scoretext.text = "Score: " + score;
highscoretext.text = "High Score: " + highscore;
}
}
GAME MANAGER
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static float score; // The player's score.
public static float highscore;
public Text highscoretext;
public Text Scoretext; // Reference to the Text component.
void Awake()
{
PlayerPrefs.GetFloat("HighScore");
highscore = PlayerPrefs.GetFloat("HighScore");
PlayerPrefs.GetFloat("scorepref");
score = PlayerPrefs.GetFloat("scorepref");
}
void Update()
{
if (score > highscore)
{
highscore = score;
PlayerPrefs.SetFloat("HighScore", score);
}
PlayerPrefs.SetFloat("scorepref", score);
Scoretext.text = "Score: " + score;
highscoretext.text = "High Score: " + highscore;
}
}
Thank you for your time!
Your answer
Follow this Question
Related Questions
Loading and Saving High Score 1 Answer
How to save progress? and not delete values on load 1 Answer
Saving highscore for multiple scenes 1 Answer
Retstart Key in C# or Javascript 1 Answer
How do I restart a scene on collision? 0 Answers