Adding weapon slots to the inventory

How to add weapon slot to the equipment state so that you can change weapons on key press

This is tricky, since the Dictionary we use to store equipped items is by nature a “One Equipment Slot, One Item To Fill It” setup…
So you’lll need to make some adjustments to EquipmentSlotUI…

First, you’ll need to add a value to the EquipLocation Enum… something like EquipLocation.BackupWeapon

In EquipmentSlotUI, you’ll need to have the MaxAcceptable do a check to see if the UI’s slot is BackupWeapon. If it is, then accept any EquipLocation.Weapon.

Equipment.AddItem only logs an error if the wrong type of equipment for the slot is added, but it should still equip the item… If you comment out the Debug.Assert line, you should be able to load a weapon into equippedItems[EquipSlot.Backup].

Then it’s a matter of swapping the weapons… I would probably do this in Equipment itself… Make an update loop that polls Input for the key you wish to use to swap the weapons… if it does, first check to make sure that there is something in the backup slot. If there is, swap the contents of the Weapon slot and the Backup slot and call equipmentUpdated.

Thank you, I will try it out

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.