Im following the Adventure game tutorial to build an Inventory, in the tutorial they are only using 4 item slots, I need a few more than that. But when I try to add even one more slot I get the following errors when i try to click on the editor down arrow (on the far right) “for item slot 4”:
All I have done is change the number of slots from 4 to 5:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Inventory : MonoBehaviour
{
public Image[] itemImages = new Image[numItemSlots];
public Item[] items = new Item[numItemSlots];
public const int numItemSlots = 5;
public void AddItem(Item itemToAdd)
{
int id = itemToAdd.id;
if (items.Length <= id)
return;
if (items [id]== null)
{
items[id] = itemToAdd;
itemImages[id].sprite = itemToAdd.sprite;
itemImages[id].enabled = true;
return;
}
}
public void RemoveItem(Item itemToRemove)
{
for (int i = 0; i < items.Length; i++)
{
if (items *== itemToRemove)*
{
items = null;
itemImages*.sprite = null;*
itemImages*.enabled = false;*
return;
}
}
}
}