/// <summary> /// Put an object in an inventory slot /// </summary> public void AddObject(PlayerObjectScript obj, int slotIndex) { // can't add object if inventory is full if (slotIndex != -1) { inventory[slotIndex].SetItem(obj); } }
public void SetItem(PlayerObjectScript obj) { item = obj; stack++; if (obj == null) { stack = 0; } }
public void Use() { if (stack > 0) { stack--; } if (stack == 0) { item = null; } }
public PlayerInventorySlot() { stack = 0; item = null; }
/// <summary> /// Set image associated to the object in the UI slot item /// </summary> /// <param name="obj"></param> /// <param name="index"></param> public void SetItemUISlot(PlayerObjectScript obj, int index) { inventorySlotUI[index].transform.GetChild(1).GetComponent <Image>().sprite = obj != null?obj.GetSprite() : defaultInvImage; }