How it works...

We have created one simple panel (Panel-background) with title UI Text as a child GameObject at the top of the game canvas, which shows a grayish background rectangle and the title text Inventory. This indicates to the player that this part of the screen is where the inventory HUD will be displayed.

To illustrate how this might be used to indicate a player carrying stars, we added a smaller panel for one slot in the inventory with a circular background image, and in that added a star icon a child GameObject. We then duplicated the slot panel two more times, positioning them 70 pixels apart. We then disabled (make inactive) the star icon of the third slot, so that the an empty slot circle is shown.

Our scene presents to the user a display indicating two out of a possible three stars are being carried. This recipe is a good start for a more general-purpose approach to creating inventory UIs in Unity, and we'll build from it in some of the following recipes in this chapter.

We'll learn how to limit the player's movement to prevent their character moving into the rectangle of HUD items like this in Chapter 12, Controlling and Choosing Positions.