Hiding and showing the Canvas
We have decided that the UI in our game will be made up of three simple views:
- MenuView
- InGameView
- GameOverView
We have created most of the MenuView. I am using two terms here, View and Canvas. In our simple game, both of them will mean the same thing. MenuCanvas is just the visible part of MenuView. Keep that in mind.
The simplest way to toggle the view's visibility is by enabling and disabling the Canvas component. Let's test how it works without the code for now:
- Press Play in Unity.
- Select the MenuCanvas game object in the Hierarchy window.
- Disable the Canvas element, marked here:
- As the Canvas component is responsible for rendering the UI in the scene, disabling it will hide the content of all UI elements within the canvas.
Note
Note once again that disabling the Canvas component will hide all UI elements within the canvas. It will also disable all events handled by the Event System.
It's been a while since we wrote some code. Let's implement the...