Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 defining 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...