I'm a beginner at 2D Unity game development and this is my first game. In this game I have two scenes - one is playing scene and another is game over scene. When I try to display the high score in game over scene, it is not working for me. Here is the code I tried:
public class highscore : MonoBehaviour {
public Text hscore;
private void Start() {
hscore.text = PlayerPrefs.GetInt("highscore", 0).ToString();
}
public void Update() {
if (GetComponent<Score>().score > PlayerPrefs.GetInt("highscore")) {
PlayerPrefs.SetInt("highscore", GetComponent<Score>().score);
hscore.text = GetComponent<Score>().score.ToString();
}
}
}
It freezes the game over scene and nothing else s working on that. Does anyone know what the problem is? Any help would be useful. Thanks in advance.