Creating a C# inventory slot UI to display scripted components
In the previous recipe, we started to work with UI panels and images to create a more general-purpose GameObject for displaying inventory slots, as well as images to indicate what is stored in them. In this recipe, we will take things a little further with the graphics and also create a C# script class that works with each inventory slot object:
Figure 3.23: Example showing stars inventory panel, with three slots
As shown in the above screenshot, in this recipe, we’ll create a UI (and scripts) for an inventory that has three locations for stars, and three more for keys, using colored and gray icons to indicate how many have been collected.
Getting ready
This recipe adapts the previous one. So, make a copy of the project from the previous recipe and work on this copy.
For this recipe, we have prepared a folder named _Scripts
in the 03_06
folder.
How to do it...
To create a C# inventory...