Search Unity

Question Can you do "button not pressed" using Input System in Send Messages

Discussion in 'Input System' started by AdamButcher, Jan 8, 2023.

  1. AdamButcher

    AdamButcher

    Joined:
    Aug 19, 2018
    Posts:
    1
    I'm making a simple FPS prototype. I want to be able to shoot when I hold down the Fire button.

    As I'm using the Unity Starter FPS controller, I want to keep my Player Input in the "Send Messages" mode (not "Invoke Unity Events"). However in "Send Messages" mode, I don't have access to CallbackContext, so I can't find interactions like performed/hold etc.

    Currently this is my code.

    void OnFire()
    {
    //shoots gun
    }

    It works every time I tap the button, but not when I hold it. I could turn on a FireHeld bool, but I don't know how to turn it off as I can't find a way of saying "If Fire not pressed".

    Any help??
     
  2. unity_3326B667FF9D1AFF851B

    unity_3326B667FF9D1AFF851B

    Joined:
    Nov 4, 2022
    Posts:
    1
    Yeah, You can do something like this:
    void OnFire(InputValue value)
    {
    if (value.isPressed)
    {
    // You press the button
    }
    else
    {
    // You unpressed the button
    }
    }