Choosing an empty Inventory Slot

Hey,

At 7:05 we check to see if the active slot has an InventorySlot component, and we subsequently null the CurrentActiveWeapon and return early if it doesn’t.

Would this if statement ever trigger? Even when the player presses 4 or 5, the active slots would have an InventorySlot component, even if they were empty? Or am I missing something?

You can just add .GetWeaponInfo() onto the end if this is an issue, though.

1 Like

If i remember correctly it checks if the slot is empty so if it is then we return out otherwise we get an error that pops up in the lecture.

In every case there is more than one way to do things :slight_smile:

The way it’s set up by the end of Part 1 (and it’s not tested in Part 2) pressing 4 or 5 gives an error. Adding .GetWeaponInfo() to the end of the check, as suggested, sets the active weapon to null and highlights the appropriate inventory slot without generating an error.

Edit:

Inventory Section Cleanup uses if(transform.GetChild(activeSlotIndexNum).GetComponent<InventorySlot>().GetWeaponInfo() == null) to fix this error.

1 Like

Privacy & Terms