Culinary Crusaders - Unity 3D
Integrating Picking up items into the UI and Inventory
27th March 2025
With the player interaction, we wanted the items to be displayed on the user interface to show the players what item they have. The best way to go about this was creating a basic inventory system that stores one item per player and they are able to drop it at any point in the game.
I first start by creating a script and naming it Inventory manager, where the items will be managed. Then i delcare a list variable for the players items in order to store them.
In addition to the inventory script, I have also created a HUDManager script. From this script, I wlll create a method that updates the UI so that the item is displayed in the players icon.
I first start by declaring an array of Images for the players Icons to display the item images.
After this, I create a method for the item to be stored into the list, making sure that the player index is a valid and is within the range of the player items list size, otherwise it will cause runtime errors. This method will be called once the player picks up an item.
I then create a method for updating the UI itself, passing through the player index and item via the item class. (note: the item class script is attached to each item in the inspector, and the information is passed through this method once picked up)
Again, the player index must be valid and within the scope of the image array size. From here, I set the image of the player icon to the image of the item. The image of the item is pre-set in the item class component that is attached to the item, and is retrieved once the item is picked up.