Search Unity

Question Checking for Interaction

Discussion in 'Input System' started by arun-muralidharan, Dec 8, 2020.

  1. arun-muralidharan

    arun-muralidharan

    Joined:
    Jun 8, 2020
    Posts:
    3
    Hello!

    I'm pretty new to this; so, forgive me if this is a silly question.

    I'm trying to check the interaction of the input from the context to see if it is a tap or slowtap. Currently, I have the following code to do this check, but I'm not sure if this is the most elegant way. Is there a better way to do this?

    Code (CSharp):
    1.  
    2. private int InputState(InputAction.CallbackContext context)
    3.     {
    4.         if (context.interaction.GetType().Name == "TapInteraction") return 1;
    5.         else if (context.interaction.GetType().Name == "SlowTapInteraction") return 2;
    6.         else return 0;
    7.     }
    8.  
     
    Last edited: Dec 8, 2020