Working with a canvas
In Unity, we can use a canvas as a container for UIÂ components. Canvases are GameObjects, and the UI components are the visual components we want on the screen during gameplay. In this section, we will create a canvas and then add and configure the necessary UI components to match our HUD's design from the previous section.
Adding the canvas
Here are the steps for adding a canvas for our UI:
- Right-click in an empty area of the
Hierarchy
panel and selectUI
|Canvas
. You can review the details of the canvas in theInspector
panel.Â
Note
You will note, in the Hierarchy
panel, that Unity created an EventSystem
when you created your canvas. This system is used to manage user input.
- Change the new canvas GameObject's name fromÂ
Canvas
toHUD_Canvas
. Using self-descriptive names for our GameObjects is considered good development practice. No other changes to any of the canvas properties are necessary.
Adding the health bar UI components
Next, we will create the UI components to display...