Exemple #1
0
 private void ShiftItems(Scriptable_Base newItem)
 {
     for (int i = 0; i < items.Count; i++)
     {
         // shift items to the left unless it is the last index, in which case place the newItem there
         if (i + 1 != items.Count)
         {
             items[i] = items[i + 1];
         }
         else
         {
             items[i] = newItem;
         }
     }
 }
Exemple #2
0
    public void AddItem(Scriptable_Base newItem)
    {
        int availableSlotIndex = items.IndexOf(null);

        // if there is no more room in the inventory, remove the first item
        if (InventoryIsFull())
        {
            availableSlotIndex = maxInventorySize - 1;
            ShiftItems(newItem);
        }
        // Increase item count if Inventory is not full
        else
        {
            currentItemCount++;
        }

        print($"{player.Name} picked up {newItem}");
        items[availableSlotIndex] = newItem;
    }