Lesson 6: Fix a Bug

At this point your game should be almost completely finished, with the exception that we have an error on our Start_Menu scene.

Fix the Bug

When you have a “bug” in your code, it means that something isn’t working right. Play your game from the start menu, and you will see the following error in your console.

The problem is that we haven’t assigned a gameObject to the highScore variable that we declared in our LevelManager when we are on the Start_Menu scene, but since there is no gameObject in this scene to assign to the variable, we need to modify our code.

The Solution

We’re going to modify our code to check what level we are on and only run the code when we are not on the Start_Menu scene. Modify your LevelManager script as in the example below.