Hi all,
I have ran into an issue I have been wracking my brain over all morning so I decided to see if anyone here had some input. Sorry for the long explanation and hopefully the explanation makes sense.
I am trying to work with two custom classes, one is Item and one is TurretLoc.
I have a ship panel that has 7 weapon slots, slot0 through slot6. In my Inventory Script I have a List called equippedItems that collects all weapons in those 7 weapon slots and then sorts them by where they are so that Slot0 = IndexOf(0), Slot1 = IndexOf(1), and so on. This list seems to work fine as I can see in the inspector when I have a Gun on slot 2, another Gun of the same type on slot 3, and a Mining Gun on Slot 4. The rest of the slots are filled with empty Items in order to keep the index proper.
Now on my ship controller I have that second class called TurretLoc and a List called turrets. This class has a int slotNumber, and a string ItemName. I preset the TurretList up to have 7 objects with the slotNumber predefined as 0 through 6 to match the ship panel. So my goal is to collect the equippedItems list, match with the slotnumber on the TurretList and filled out the itemName with the itemName in the EquipedWeapons list.
Here is where things start to go wrong. This works with Unique items but if I try to put a 2nd or 3rd of a same item into a slot it is just ignored.
Here is the code I have been fiddling around with. I am assuming I am just thinking about this the wrong way. Would appreciate any input, thanks!
public void UpdateWeaponModels()
{
foreach (Item x in inv.equippedItems)
{
foreach (TurretLoc tur in turrets)
{
if (tur.Slot == inv.equippedItems.IndexOf(x))
{
tur.itemName = x.itemName;
}
}
}
}