- Home /
Question by
Fierce Waffle · May 11, 2011 at 03:24 AM ·
buttondownhold
Detect Button Being Held Down
I want to detect if I have the F Key held down for 0.5 seconds, to call the function PickUp();
Comment
I guess there is no way to stop such kind of simple question in UnityAnswers.
Best Answer
Answer by Dreamer · May 11, 2011 at 03:32 AM
var count:float=0.5;
function Update () { if (Input.GetKeyDown ("f")){ count-=time.deltaTime; if(count<0){ PickUp(); count=0.5; } } else count=0.5; }
Use
Input.Get$$anonymous$$ey("f")
{
//...
}
Because Get$$anonymous$$eyDown will decrement your count var each time the f key is pressed, not the duration.
Your answer
Follow this Question
Related Questions
How to set Input Buttons 2 Answers
Detect Mouse Click OnGUI 1 Answer
Input press to play different animation to input hold? 0 Answers
How to make a physics based jump with button hold effect 0 Answers