How can we cope with many inventory slots that don't fit in the space provided? One solution is to add a scroll bar so that the user can scroll left and right, viewing five at a time, say, as shown in the following screenshot:
Figure 3.29 – Example game with a horizontal scroll bar
Let's add a horizontal scroll bar to our game. This can be achieved without making any C# code changes; that is, everything can be done through the Unity UI system.
To implement a horizontal scroll bar for our inventory display, we need to do the following:
- First, increase Height of Panel-background to 110 pixels.
- In the Inspector window, set the Child Alignment property of the Grid Layout Group (Script) component of Panel-slot-grid to upper-left. Then, move this panel to the right a little so that the inventory icons are centered on the screen.
- Add a UI Panel to Canvas and name it Panel-scroll-container. Then, give...