I really don’t know what’s going wrong here. I’ve got an inventory class, I’m trying to add the two basic functions, AddItem() and RemoveItem(). Yet, for some reason, despite the fact that I’ve double checked every part of the script that involves adding an item, and sounded it out so that I was speaking back to myself, everything that the script did.
using UnityEngine;
using System.Collections;
public class Inventory : Items {
GameObject[] inventoryArray = new GameObject[6];
public GameObject itemPlaceholder;
GameObject selectedItem;
void Start ()
{
itemPlaceholder = GameObject.Find ("InventoryPlaceholder");
GameObject equippedItem = inventoryArray[1];
}
void Update ()
{
if(Input.GetKeyDown("l"))
{
RemoveItem(i : itemPlaceholder);
}
if (Input.GetKeyDown("k"))
{
AddItem(i : itemPlaceholder);
}
if (Input.GetKeyDown ("i"))
{
DebugDisplayInventory();
}
}
void AddItem(GameObject i)
{ //Checks through inventory for null spaces, then adds
byte j = 0; //GameObject i to the the null spot, i being the item the
for (j = 1; j < inventoryArray.Length; j++) //player wants to add. Break terminates the function once the
{ //item is added to prevent adding more than one item to the
if (inventoryArray [j] = null) //inventory's null spaces.
{
inventoryArray [j] = i;
break;
}
}
}
void RemoveItem(GameObject i) //Used for dropping NOT placing, should be the only possible method of removing an item
{ //other than PlaceItem();
byte j = 0;
for (j = 1; j < inventoryArray.Length; j++)
{
if(inventoryArray[j] = i)
{
inventoryArray[j] = null;
}
}
}
void DebugDisplayInventory()
{
print ("Debug Inventory:");
for (int i = 0; i < inventoryArray.Length; i++)
{
print (inventoryArray*);*
-
}*
- }*
}
I really don’t understand why this won’t execute and/or actually add an item. I can run the debug inventory function just fine but it always turns up 6 inventory slots of null, even after attempting to use AddItem().