Exemple #1
0
    public void Add(ItemObject itemObj)
    {
        // Names are hard... Within the itemObject is the information of the object which is in a scriptable object of name 'item.'
        Item item = itemObj.item;

        if (!item.isDefaultItem && items.Count < maxInventory)
        {
            items.Add(item);
            onItemChangedCallback();
            itemObj.Despawn();
        }
        else
        {
            if (item.name == "Health Potion")
            {
                if (curHpPot < maxPotions)
                {
                    curHpPot++;
                    itemObj.Despawn();
                    return;
                }
                else
                {
                    Debug.Log("You're already carrying max Health Potions!");
                }
            }
            else if (item.name == "Mana Potion")
            {
                if (curManaPot < maxPotions)
                {
                    curManaPot++;
                    Destroy(itemObj);
                    return;
                }
                else
                {
                    Debug.Log("You're already carrying max Mana Potions!");
                }
            }
            else if (itemObj.tag == "Weapon")
            {
                equipWeapon(item);
                gm.RefreshItem(currentWeapon);
                onItemChangedCallback();
                itemObj.Despawn();
            }
            else if (itemObj.tag == "Armor")
            {
                equipArmor(item);
                onItemChangedCallback();
                itemObj.Despawn();
            }
            else
            {
                Debug.LogError("Item incorrectly labeled as Default Item.");
            }
        }
    }