Ejemplo n.º 1
0
 public void OnCollection()
 {
     if (itemType == ItemTypes.Money)
     {
         Inventory.money += amount; // Add to money
     }
     else if (itemType == ItemTypes.Craftable || itemType == ItemTypes.Consumables)
     {
         int found    = 0;
         int addIndex = 0;
         for (int i = 0; i < Inventory.inv.Count; i++)
         {
             if (itemID == Inventory.inv[i].Id)
             {
                 found    = 1;
                 addIndex = 1;
                 break;
             }
         }
         if (found == 1)
         {
             Inventory.inv[addIndex].Amount += amount;
         }
         else
         {
             Inventory.inv.Add(ItemData.CreateItem(itemID)); // Pick up and add to inv
             if (amount > 1)
             {
                 for (int i = 0; i < Inventory.inv.Count; i++)
                 {
                     if (itemID == Inventory.inv[i].Id)
                     {
                         Inventory.inv[addIndex].Amount = amount;
                     }
                 }
             }
         }
     }
     else // Weapons or armour/misc
     {
         Inventory.inv.Add(ItemData.CreateItem(itemID)); // Pick up and add to inv
     }
     DragAndDropInventory.AddItem(itemID);
     Destroy(gameObject); // Remove from world
 }
Ejemplo n.º 2
0
 public void OnCollection()
 {
     if (itemType == ItemTypes.Money)
     {
         Inventory.money += amount; // add to money
     }
     else if (itemType == ItemTypes.Craftable || itemType == ItemTypes.Consumables)
     {
         int found    = 0;
         int addIndex = 0;
         for (int i = 0; i < Inventory.inv.Count; i++)
         {
             if (itemId == Inventory.inv[i].Id)
             {
                 found    = 1;
                 addIndex = i;
                 break;
             }
         }
         if (found == 1)
         {
             Inventory.inv[addIndex].Amount += amount;
         }
         else
         {
             Inventory.inv.Add(ItemData.CreateItem(itemId)); // pick up and add to inventory
             if (amount > 1)
             {
                 for (int i = 0; i < Inventory.inv.Count; i++)
                 {
                     if (itemId == Inventory.inv[i].Id)
                     {
                         Inventory.inv[i].Amount = amount;
                     }
                 }
             }
         }
     }
     else // Weapons or Armour/Misc
     {
         Inventory.inv.Add(ItemData.CreateItem(itemId)); // pick up and add to inventory
     }
     DragAndDropInventory.AddItem(itemId);
     Destroy(gameObject); // Remove the object this script is attached to from the world
 }