For my game i have the score update in the game level and want the player to be able to see his/her personal high score from the menu level. i want the high score update if the score from the game level becomes greater then the current high score. at the moment these are the two scripts that i have. the first handles updating the score in the game level. the second script handles updating the score in the main menu. currently this does not seem to be working as high score always remains 0.
Game manager
public Text scoreText;
public Transform player;
float playerHeightY;
bool playerIsAlive;
public int score;
public int highScore;
// Use this for initialization
void Start ()
{
playerIsAlive = true;
score = 0;
highScore = 0;
PlayerPrefs.GetInt ("HighScore", highScore);
}
// Update is called once per frame
void Update ()
{
playerHeightY = player.position.y;
scoreText.text = "Score: " + score;
if (playerHeightY > score && playerIsAlive)
{
score = (int)playerHeightY;
}
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt ("HighScore", highScore);
PlayerPrefs.Save();
}
}
}
{
high score script
Text text;
public int highScore;
// Use this for initialization
void Start ()
{
text = gameObject.GetComponent<Text> ();
}
// Update is called once per frame
void Update ()
{
PlayerPrefs.GetInt ("HighScore", highScore);
text.text = "High Score : " + highScore.ToString ();
}
}