I’ve almost got it working now. So, when the game starts I start with defaultWeapon (unarmed). I can see this item as equipped. I’m not able to remove it (thankfully). Once I pick up a new weapon (Sword), I can’t equip it by dragging it over to the weapon slot in the equipment tab. I can however equip it when using your earlier method that I implemented from here: Right clicking an item in the inventory - Unity Courses / Ask - GameDev.tv
This functions correctly, and replaces the defaultWeapon without adding defaultWeapon it to the inventory. I am able to remove the sword by dragging it back to the inventory, and the defaultWeapon correctly returns to unarmed. So the only outstanding issue is being able to drag weapons into the equipment tab to replace defaultWeapon.
So, we’re almost there! I’ll post my updated methods below. It’s probably something small that I’ve done in the wrong order!
From Inventory.cs:
public bool AddToFirstEmptySlot(InventoryItem item, int number)
{
number = CheckItemStores(item, number);
if (number <= 0) return true;
int i = FindSlot(item);
slots[i].item = item;
slots[i].number += number;
if (inventoryUpdated != null)
{
inventoryUpdated();
}
return true;
}
Added to Inventory.cs:
private int CheckItemStores(InventoryItem item, int number)
{
foreach (var store in GetComponents<IItemStore>())
{
number -= store.AddItems(item, number);
}
return number;
}
Updated in Inventory.cs:
public bool AddItemToSlot(int slot, InventoryItem item, int number)
{
number = CheckItemStores(item, number);
if (number <= 0) return true;
if (slots[slot].item != null)
{
return AddToFirstEmptySlot(item, number); ;
}
var i = FindStack(item);
if (i >= 0)
{
slot = i;
}
slots[slot].item = item;
slots[slot].number += number;
if (inventoryUpdated != null)
{
inventoryUpdated();
}
return true;
}
Thanks again for the help, we’ve almost got it working!