Search Unity

Creating a Toggle On Button Press

Discussion in 'Input System' started by FEZ_GG, Jan 13, 2022.

  1. FEZ_GG

    FEZ_GG

    Joined:
    Jul 7, 2020
    Posts:
    2
    I'm trying to incorporate an auto-run button into a 2D platformer, and what I have is working, but I'd like it to be more polished.

    Code (CSharp):
    1. public bool dashAuto = false;
    2. public void GetAutoDashInput(InputAction.CallbackContext callbackContext)
    3.     {
    4.         dashAuto = !dashAuto;
    5.     }
    Upon pressing and releasing the Autorun key, the toggle works successfully. However, I was looking for something that would work immediately upon pressing the key, and not need to release it in order to change the boolean. How would this be done?