- Home /
The question is answered, right answer was accepted
Do something while key is pressed and held down.
I am sorry for this nooby question, and I have seen similar questions on the forum, but none of the solutions are working for me. Basically 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 doesnt continuously keep increasing, it will only increase again if i let go and repress the button. Any help would be really appreciated. Thanks
var testNumber : int = 0;
var testText : GUIText;
function Start () {
}
function Update () {
if(Input.GetButtonDown("Fire1"))
{
testNumber += 1;
}
testText.text = "" + testNumber;
}
Answer by robertbu · Mar 07, 2013 at 12:27 AM
Use "Input.GetButton()" instead of "Input.GetButtonDown()". Input.GetButtonDown() only returns true for the frame in which the button was pressed.