Example #1
0
    /// <summary>
    /// Removes a certain amount of the item in the inventory slot
    /// </summary>
    /// <param name="amount"></param>
    /// <returns> This returns the item with the amount that was removed, whatever was left  stays  inn the inventory slot</returns>
    public override Item RemoveItem(int amount = 1)
    {
        Item temp = Instantiate(HeldItem, HeldItem.transform);

        temp.transform.parent = null;
        SlotWeight           -= HeldItem.itemWeight * amount;
        ParentInventory.ReduceWeight(HeldItem.itemWeight * amount);
        if (amount > HeldItem.stackCount)
        {
            amount = HeldItem.stackCount;
        }
        if (amount == HeldItem.stackCount)
        {
            Destroy(HeldItem.gameObject);
            HeldItem = null;
        }
        else
        {
            if (temp.stackCount - amount > 0)
            {
                temp.RemoveFromStack(temp.stackCount - amount);
            }

            HeldItem.RemoveFromStack(amount);
        }
        SetHeldItem();
        UpdateItemDisplay();
        return(temp);
    }