How to stop player from picking up and displaying more than one item at a time

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobeQGamings

In a 2D game I’m making, the player can pick up items by clicking on them, and the item will then be displayed above their head. As such, I want them to only be able to have one item picked up at a time. How can I block the player from clicking and collecting a second item while they are already holding one?

:bust_in_silhouette: Reply From: TheIronGod

Set a bool on the player, if the player has an item it’s true and otherwise false. Then in your method to pick up an item, have it check that bool before it works. So, on your player something like:

var hasItem = false

Then in your pick up method:

if hasItem == false:
     hasItem = true

Thanks, this seems to be working out! I appreciate the help.

TobeQGamings | 2022-11-22 02:44