Search Unity

Question "Adding" and "Removing" Button Presses

Discussion in 'Input System' started by Hackworth, Jul 23, 2020.

  1. Hackworth

    Hackworth

    Joined:
    Apr 28, 2020
    Posts:
    4
    Been beating my head against this concept for a while now and reaching out for help. Allow me to paint the picture.

    Using a gamepad, I would like the player to be able to press say, the buttonEast, then while pressing East, *add* the South button, and finally, release the East button and have South be the only button pressed. If you are of an age to remember the game "Super Smash T.V.", the player shooting mechanic was to use the gamepad buttons (N,S,E,W) and to be able to dynamically combine them to shoot diagonally. I've tried the button with modifiers, but seemingly, they have to be depressed together *simultaneously* in order to trigger a NE or NW event. I am doing this in the context of the 'Unity Event' set up.

    Am I missing something fairly obvious? I am fairly new to this type of programming and my instinct is telling me that there is some sort of event listener that would be more effective than this method seen below. Can anyone provide any advice on the matter? Thanks!

    Code (CSharp):
    1. public void GetInput(InputAction.CallbackContext ctx)
    2.     {
    3.         //if (ctx.phase != InputActionPhase.Performed)
    4.             //return;
    5.  
    6.         if (Gamepad.current.buttonSouth.isPressed)
    7.         {
    8.             if (Gamepad.current.buttonEast.isPressed)
    9.             {
    10.                 Debug.Log("Southeast");
    11.             }
    12.            
    13.             Debug.Log("South");
    14.         }
    15.  
    16.         if (Gamepad.current.buttonEast.isPressed)
    17.         {
    18.             if (Gamepad.current.buttonSouth.isPressed)
    19.             {
    20.                 Debug.Log("Southeast");
    21.             }
    22.  
    23.             Debug.Log("East");
    24.         }
    25.     }
    26. }
     
  2. therastal

    therastal

    Joined:
    Jun 13, 2019
    Posts:
    1
    The easiest way I can think of would be to set up a Shoot action as a 2D Vector composite, then have Up = Button North, Down = Button South, etc. Then you could just have the projectiles take the input from that as the direction they go in.