Remove item from list when click button

hello all i have a list of items , so when i collect the items they insert into the inventory at random , based on which item i collect , so i have

public void AddItem(Item item) { Items.Add(item) }

to remove i tried with

public void RemoveItem(Item item) { Items.Remove(item) }

when i click on the button, but it starts to delete starting from the last item , so if i collect 6 items , and i click on the button to delete the first item , it deletes the last item and not the item specific i want to delete, should i use a (foreach) i guess, how could i use that?

Hi, not sure what exactly is happening here. If you pass the refference to the “item” correctly it should work. You can also try Items.RemoveAt(int index) and pass the index, instead of a reference.