Do something while key is pressed and held down

This nooby question - I have seen similar questions on the forum, but none of the solutions are working for me. What I am trying to do is while the "Fire1" key is pressed, and held down I want to increase the value of testNumber by 1 continuously.

Currently when I run this script I press the "Fire1" button and hold it down, but the value doesn’t continuously keep increasing, it will only increase again if I let go and repress the button.

Any help would be really appreciated.

Code below is not C# but JS-like, now obsolete, Unity Script
var testNumber : int = 0;
var testText : GUIText;
  
function Update ()
{
    if( Input.GetButtonDown("Fire1") )
    {
        testNumber += 1;
    }
    testText.text = "" + testNumber;
}

Thanks

1 Like

Use Input.GetButton instead of Input.GetButtonDown(). Input.GetButtonDown() only returns true for the frame in which the button was pressed.