Game Development Reference
In-Depth Information
Creating the inventory script
For our inventory, we'll only use one script, so let's get it started.
Creating and naming the script
The first thing we need to do is to create a new C# script and name it Inventory .
When you open the script, delete the Start and Update functions, leaving an empty
class for us to use.
Adding the necessary variables
First, add this using statement where the other using statements are. The using
statement will be needed so that we can use the List container variable:
using System.Collections.Generic;
Now, let's add the variables we require and place them after the opening class defin-
ing bracket:
bool showInventory = false;
public Rect inventoryRect = new
Rect(Screen.width / 2, Screen.height / 2, 400,
400);
public GameObject EmptyObject;
public int InventorySize = 9;
public GameObject[] invItems;
public GameObject[] QuickItems;
List<KeyValuePair<int, GameObject>> items = new
List<KeyValuePair<int, GameObject>>();
List<KeyValuePair<int, int>> itemCount = new
List<KeyValuePair<int, int>>();
Search WWH ::




Custom Search