Beispiel #1
0
 public void UseItem(int index)
 {
     if (index < items.Count && items[index] is Consumable)
     {
         Consumable selectedItem = items[index] as Consumable;
         selectedItem.UseItem();
         if (selectedItem.GetItemCount() == 0)
         {
             items.Remove(items[index]);
         }
     }
     GenerateInventoryIcons();
 }
Beispiel #2
0
    void GenerateInventoryIcons()
    {
        foreach (var item in inventoryItems)
        {
            Destroy(item);
        }
        inventoryItems = new GameObject[items.Count];
        int count = 0;

        foreach (var item in items)
        {
            if (item is Consumable)
            {
                inventoryItems[count] = Instantiate(mConsumablePrefab, transform);
                Consumable tempItem = item as Consumable;
                inventoryItems[count].GetComponentInChildren <Text>().text = "X" + tempItem.GetItemCount();

                inventoryItems[count].GetComponent <ConsumableSlot>().mID = count++;
            }
            else if (item is Equipment)
            {
                inventoryItems[count] = Instantiate(mEquipmentPrefab, transform);
                if (item is Weapon)
                {
                    inventoryItems[count].GetComponentInChildren <Image>().sprite = weaponImage;
                    EquipmentCompare(item, count);
                }
                else if (item is Armor)
                {
                    inventoryItems[count].GetComponentInChildren <Image>().sprite = armorImage;
                    EquipmentCompare(item, count);
                }
                inventoryItems[count].GetComponent <EquipmentSlot>().mID = count++;
            }
        }
    }