Slightly Deeper Dive into Interactions
--
In previous articles I’ve gone over Interactions briefly. Actions can have several different interactions and you can code out logic based on the type of interaction.
Understanding this requires a basic understanding of that fact that Interactions have a set of different phases they can go through in response to receiving input. Waiting, Started, Performed, Canceled
. We’ve gone over this in the past.
Here is an example of an action having multiple interactions.
The Player action map has an action called Interact
. That action has 2 different interactions: a Hold type and a Press type. So when I press the interact button I want certain things to happen and when I hold the button I want different things to happen.
I have some logic set up for this here:
Disregard the Interactable_Zone_onInteractionComplete() and other logic I’ve built around this. This isnt the prettiest implementation, but what I want to point out is the if statement itself.
If the interaction is a HoldInteraction do this stuff. Otherwise do this stuff. The `UnityEngine.InpustSystem.Interactions` namespace is what allows you to check for different interaction types on the same Action!
This is super useful for lots of reasons. In the next articles I’ll cover a project I was assigned. In this project I have to convert all input interactions from the legacy input system to the new input system. This project will challenge and help reinforce your understanding of the new input system. Hope to see you there!