Press and Hold interactions for player


Hey everyone, back again for our weekly look at Hopeless Forager's development.

The interesting thing I came across and wanted to share this week, was actually a code that eluded me for a bit. I wanted to add a new interactable object that would need the player to press and hold the interact key in order to fully work (basically, I wanted to create a "repair section" object that the player would have to continuously hold down E for a set period of time to fix).

As I'm not fully knowledgeable with Unity's input system, I had some trouble figuring out the best way to approach this, especially since I wanted to limit the player's other inputs when doing this "fixing" interaction.

The solution I found was to separate the Player's usual input commands from the interaction command, allowing me to disable general functionalities while keeping track of the held down interaction command to see when it starts or is cancelled.

Anyway, that's all for today, tchau, everyone!
Victor.

Leave a comment

Log in with itch.io to leave a comment.