Game Development Reference
In-Depth Information
The showInventory variable will be used when we activate an input. This is how
we determine when to and when not to show the inventory GUI. Next, we have a
Rectangle variable, that we'll use to determine where we put the inventory GUI and
what size it should be. By default, we set the X and Y positions to the center of the
screen.
Our next variable is a GameObject; in the Inspector panel we will set this as an
empty object. We'll be using the empty object in our inventory as a placeholder when
there is no item to be placed there. The next variable, aptly named InventoryS-
ize , will determine the size of our inventory.
The next two variables are GameObject arrays. We use these to hold the actual
GameObject items that we will hold in our Inventory. InvItems will hold the
GameObjects that are in our inventory and QuickItems will hold the GameObjects
that the player wants as their quick-items.
Lastly, we have two lists for our final variables. The first one will hold the GameObject
items within our inventory; the list is made up of KeyValuePairs . The key will be
the ID of our item and the value is a GameObject, which is the item in our inventory.
Our next list is also made up of KeyValuePairs and both the Key and Value are
integers. The Key will be our ID that will match itemCount to the correct inventory
item. The Value will be the actual number of items that we have.
Initializing our inventory
Time for our first function! This method will be used to create our inventory for the
first time.
Creating the initializer
Let's create our initializer by adding the following function to the script:
void InitializeInventory()
{
invItems = new GameObject[InventorySize];
for(int i = 0; i < InventorySize; i++)
Search WWH ::




Custom Search