I want to know how to drop my item with a keyboard button

I want to be able to remove the items from my inventory when I push Q, this is the code for picking up the items

public class PlayerInventory : MonoBehaviour
{
public InventoryObject inventory;
public void OnTriggerEnter(Collider other)
{
    var item = other.GetComponent<Item>();
    if (item)
    {
        inventory.AddItem(item.item, 1);
        Destroy(other.gameObject);
    }
  }
}

and this is how the code is adding the items

[CreateAssetMenu(fileName = "New Inventory", menuName = "Inventory System/Inventory")]
public class InventoryObject : ScriptableObject
{
public List<InventorySlot> Container = new List<InventorySlot>();
public void AddItem(ItemObject _item, int _amount)
{
    bool hasItem = false;
    for (int i = 0; i < Container.Count; i++)
    {
        if(Container*.item == _item)*

{
Container*.AddAmount(amount);
hasItem = true;
break;
_
}*

}
if (!hasItem)
{
Container.Add(new InventorySlot(_item, _amount));
}
}
}
[System.Serializable]
public class InventorySlot
{
public ItemObject item;
public int amount;
public InventorySlot(ItemObject _item, int _amount)
{
item = _item;
amount = _amount;
}
public void AddAmount(int value)
{
amount += value;
}
}

Hello :slight_smile:

Code not tested.

In PlayerInventory
class:

  public void Update()
{
  if (Input.GetKey("Q"))
            {
                inventory.RemoveItems();
            }
}

In inventoryObject class:

public void RemoveItems()
{
    Container = new List<InventorySlot>();
}