Inventory System

Sidchou
2 min readSep 23, 2022

--

Objective: create a Inventory System
a good way of creating a inventory system is using a dictionary, where a key is point to a variable. so we can use the item name as key, and the quantity as the int variable.

To declare the dictionary we start with this.

I have some prefab in the scene to pick up. (Since the instances of prefab has the (clone) at the end, we need to remove it first for checking the names in the dictionary.

To check items collected, I created a menu.

Using the text in the element, we can use them to check the dictionary. First create the list of the names.

In the script where the dictionary is created, we create a public method to be quarried.

Now we can update the text with the dictionary information.

I want to load the text every time menu is loaded.

but OnEnable runs before start, and we don't want error on the first time because the list wasn't created yet.

--

--

Sidchou

An Unity Developer who loves to create interactive and immersive experiences.