Help with Coding Single High Score into scene...!

I’m having issues coding a high score into our game… I can get it to display the text - “High Score” where I need, but I can’t get the SingleHighScoreManager to work with the GUIManager like it’s supposed to… I also need to put this in a completely separate scene which shouldn’t be too hard after I figure out how to display it.

   <param name="state">If set to <c>true</c>, sets the game over screen on.</param>
    public virtual void SetGameOverScreen(bool state)
    {
        GameOverScreen.SetActive(state);
 Text gameOverScreenTextObject GameOverScreen.transform.Find("GameOverScreenText").GetComponent<Text>();
        if (gameOverScreenTextObject != null)

            gameOverScreenTextObject.text = "HIGH SCORE :" + Mathf.Round(GameManager.Instance.HighScore);

            gameOverScreenTextObject.text = "GAME OVER

YOUR SCORE :" + Mathf.Round(GameManager.Instance.Points);

Obviously the Mathf.Round(GameManager.Instance.HighScore) isn’t what needs to be there (maybe it does and I didn’t build the method correctly). I’ve searched as much as possible to find the correct answer, but I’ve been left in the dark. I don’t know a whole lot of C#, been learning through 3dbuzz how to code but that tutorial was from 3 years ago and only is for console scripts. If you could point me in the correct direction to fix this I would greatly appreciate it.

  1. Ensure that you are actually returning an object with the transform.Find() method.
  2. Ensure that the value of GameManager.instance.HighScore matches up with what it should be.

There’s no immediate reasons why this shouldn’t work if those two things are correct because the code is very straightforward.

When working with Multiple Scenes you can use the following:

Solution #1:

The most basic fix that will correct this issue is to change the GameManager.instance.HighScore variable to a static variable. When a variable is static, it belongs to the class, not a class instance.

To elaborate a little further, any time you go from one scene to another, all of the objects that aren’t marked as “DontDestroyOnLoad()” will be destroyed from your scene. What this does is it also destroys all of the variables attached to the object. The syntax for the variable definition will be something along the lines of “Public static int HighScore = 0” or “Public static int HighScore {get; set;}”

Solution #2

Mark GameManager class as DontDestroyOnLoad() in the Awake() or Start() methods.

This will prevent the object from being destroyed, thus it will follow you from scene-to-scene. This is advantageous for data persistence, but it can cause some initial confusion. You’ll know what I mean when you start out :slight_smile: