Unity Tutorials 7 - Menus and Huds I - Menus: The Canvas
Unity Tutorials 7 - Menus and Huds I - Menus: The Canvas
I – Menus
The Canvas
Begin by creating a new scene by
clicking “File” and “New Scene”.
Save it as “mainMenu”.
Switch to 2D mode.
Click and drag the blue dots to fit the image to the canvas.
If your image is not anchored to the canvas it will not stretch with it to fit the screen
resolution. You can click and drag the arrows so that they are at the corners of the
canvas, or you can click the square shown in the image below then click the bottom-
right image in the menu that pops up.
Save your scene and double-click on your level scene in your Assets to open it.
You should still be in 2D mode. If not, switch to 2D. Now add a Canvas.
Health Bar
Go to “GameObject” and “UI” and add a “RawImage”. Change the colour to black.
Again, don't forget to change the anchor to stretch across the canvas. Also make sure
that it is parented to the canvas.
Set the Left Rect Transform to 15, the Top to 10, the Pos Z to 0, the Right to 600, and
the Bottom to 290. These specific values are not necessary, but these are the values we
will be using in the next tutorial. We are going to have the health bar decrease by
changing the Right Rect Transform when the player takes damage.
Add two empty GameObjects to the canvas and name one “livesCounter” and the other
“coinCounter”.
You can play your scene to see how everything looks, but you won't be able to see the
lives or coin counters yet. These concepts will be continued in the next tutorial.