Setting up the UI

First of all, we need to create a canvas by right-clicking in the Hierarchy panel, then UI | Canvas, and naming it HUD. Unity should automatically create an EventSystem. In case it doesn't, you can manually add it by again right-clicking and then clicking UI | EventSystem. Then, we need to create a Panel within the Canvas, and we can do it similarly to how we created the Canvas. Among the different anchor presets, we can select the one on top, as shown in the following screenshot:

Next, resize the panel so that it occupies the upper part of the screen. In the end, you should end up with something similar to the following:

If you want to be sure how the panel will appear in-game, you can switch to the game mode view. This is how the panel should appear according to our design:

We need to create one more thing: a label where we'll display the score to the player. So let's create a Text, and rename it ScoreLabel. Now, in the Inspector, we need to tweak some values of the Text Component. In particular, we want to change the font, to the one we imported before, and the font size to better fit the panel. It's important to adjust the dimensions of the box containing the text, and the anchors (in my case, I used that they stretch), and the alignment. Also, as a text we can insert the string Score: 0, so we can have a better idea of how it will look once the score starts to increase; don't worry much about it though because this text will be replaced by our script. Of course, feel free to change any other settings you'd like to fit your personal style and mood. These are the settings I used:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset