Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What to do if "Key hold down"

Discussion in 'Input System' started by Patrick_Rainer, Apr 17, 2020.

  1. Patrick_Rainer

    Patrick_Rainer

    Joined:
    Feb 26, 2018
    Posts:
    49
    Dear All

    Sorry coming up with a question again. Did read some other posts about it, but could not identify a solultion.

    How can I get a continues value if the key is hold down? In this case it the onMove method is just called by "KeyDown"...

    Code (CSharp):
    1.         public void OnMove(InputAction.CallbackContext context)
    2.         {
    3.             var direction = context.ReadValue<Vector2>();
    4.  
    5.             if (direction == Vector2.zero)
    6.                 return;
    7.  
    8.             _turnController.GetActiveTank().Move(direction);          
    9.         }
     
  2. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    429
    I know this isn't probably what you were hoping to hear, but I couldn't find a good way to get access to simple press/hold/reelase events, so I just gave up and wrapped the entire input system so that I could still use that convention.

    The default interaction will send "Started" when a button is pressed, and "canceled" when a button is released. I simply hooked into those events to flag "pressed" and "held" bools that I created.
     
    Patrick_Rainer likes this.