Get object to check list for number of specific items
I have an inventory system that is basically a list on a GameObject, when you pick up an item it destroys the item and adds the item's name to the list. I've got the inventory system set up in a working way using what can only be described as an absolute mess of basic tools. It's not very elegant but it works... kind of.
Now I want to put items from my inventory into a chest for storage, but I'm now at a roadblock because my current system would require an entire GUI object for each chest. I've searched online but i just CANNOT find ANY decent info on C# lists.
The current inventory spawns an object that displays the Item name, how many of the item you have, the individual weight, and the combined weight of all of that type of item in the inventory.
What I would like to do is have each of the spawned objects have their item type given when they are created and to constantly search the inventory list for however many of that type there is and update the amount with however many it finds.
So, I pick up a piece of "Iron Ore" the inventory has no object representing this so it creates one with the itemRef of "Iron Ore" and the given weight of one piece of that item. It would then scan the inventory list for instances of "Iron Ore" and change its count to match the found instances.
This is what I'm struggling with, I just cannot find anyone giving help in how to pull this off. I've tried different foreach
things to try and look for items and change the count to reflect the amount it finds. It either finds one and constantly updates the count into infinity, or will add 1 regardless of how many it found.
Here is a screenshot of the inventory system, I've crossed out anything irrelevant to the question, I can sort that out once I have the system working as I'd like. Every time you pick up an item that you don't have, one of these objects would be spawned into the inventory.
Here is the inventory showing 3 objects representing different items and how many I have. Working but not as I'd like (above)