I’ve always been having difficulty grasping arrays so bare with me. I’m trying to make an array that contains Items and each Item has a Quantity attached to them.
Let’s call the array Bag. In the beginning, the Bag has 1 Item and that Item has a Quantity of 5. How would I first create this?
After that, I want to be able to add new Items and a Quantity for those new Items.
In the long run, I want to be able to say “If Bag has 5 Apples, then do the following”
I hope everyone understands what I’m trying to do. If anyone can help me, please do =D
Spinaljack’s way seems pretty sound. I handled it differently.
If your creating an Inventory/Bag System, Which would be my guess, Your probably going to only allow certain items to be added into your “Bag”.
A script such as “ItemInfo.cs” In that script you can have an option if the Item is stackable or not… And when you add it to the Bag you could see if the item matches other items in your bag’s names(or whatever you want to specifiy) add it to the stack or do whatever if your stack size is at max… This is how I handled mine currently. I have no stack limit but Potions will stack properly, Drop properly based on number given as well.