Reference exceptions
Test the code by pressing Play in Unity and then clicking on the Play UI button. The SetGameState
function that we just added to GameManager
should hide the MenuCanvas
. Oops! Something is wrong. Unity is displaying an error in the Console window. Something surely went wrong. Let's take a look at the red error message, which is shown here:
In your programming career, you will come across many issues with the games or applications that you are creating. I have deliberately asked you to follow my steps to cause this issue. We will learn with experience. Beginners in programming often rely on luck while sorting issues. They blindly change something, test again, and keep going in that loop until they fix the issue by pure luck or simply give up on trying. This is a very bad approach to debugging. I want you to understand what the issue is. In most cases, Unity will try to give you an accurate description of the error in the console. Once we face an issue, we will learn...