I’m getting an argument out of range error and I don’t know how to fix it. Here is my relevant code:
/// Max allowed slots in inventory.
/// </summary>
public int maxInventorySpace = 5;
/// <summary>
/// Equips the item located at the associated index.
/// </summary>
public int currentlyEquippedItemIndex = 0;
/// <summary>
/// Items currently in inventory.
/// </summary>
public List<ItemPickUp> itemsInInventory = new List<ItemPickUp>();
/// <summary>
/// Scroll through the items with the mouse wheel.
/// </summary>
void ScrollItems()
{
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
if (currentlyEquippedItemIndex >= itemsInInventory.Count - 1)
currentlyEquippedItemIndex = 0;
else
currentlyEquippedItemIndex++;
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
if (currentlyEquippedItemIndex <= 0)
currentlyEquippedItemIndex = itemsInInventory.Count - 1;
else
currentlyEquippedItemIndex--;
}
// Select the item at the index if it is not already equipped
if (itemsInInventory[currentlyEquippedItemIndex].isEquipped == false)
{
SelectItem(currentlyEquippedItemIndex);
}
}
Unity says I’m getting the error because of this:
// Select the item at the index if it is not already equipped
if (itemsInInventory[currentlyEquippedItemIndex].isEquipped == false)
{
SelectItem(currentlyEquippedItemIndex);
}