Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How do I detact certain combination of keys?

Discussion in 'Input System' started by CHAIWOWO, May 11, 2021.



    May 29, 2020
    For example, I'm making Dead cell-like fall attack. Press S + Space button to fall attack. but Space + S won't achieve the same effect. So how can I do this?
  2. jukibom


    Aug 31, 2015
    That's not something I think is really inherent to the input system. It's more like you'd define a duck action with a key binding to S and an attack action with a key binding to Space. Then you'd manage the logic of what happens when both of those actions are occurring in some player class.

    Something like (using SendMessage)

    Code (CSharp):
    1.     public void OnDuck(InputValue value) {
    2.         // if action is a button type, event will fire on button press and release.
    3.         _ducking = value.isPressed;
    4.     }
    6.     public void OnAttack(InputValue value) {
    7.         // we probably only care about the button press for attack
    8.         if (value.isPressed) {
    9.             if (_ducking) {
    10.                 FallAttack();
    11.             }
    12.             else {
    13.                 BasicAttack();
    14.             }
    15.         }
    16.     }