- Home /
Question by
adamchakov · Apr 25, 2014 at 02:40 PM ·
getkeydowntwicespacebar
check if spacebar was pressed two times
yo guys how to count how many times i pressed the 'space bar' like : check if space bar was pressed two times then DO SOMETHING. thanks.
Comment
Answer by Graham-Dunnett · Apr 25, 2014 at 02:41 PM
Have a counter, set it to zero. If the space bar is pressed and the counter is zero start a timer and increment the counter. If the counter was one, and the timer is less than some value, then you've had two presses on the space bar, so reset the count back to zero.
Answer by Bru345 · Apr 25, 2014 at 03:23 PM
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space))
{
timesPressed +=1;
}
if (timesPressed > 2)
{
timesPressed = 1;
}
if (timesPressed == 2)
{
Debug.Log("You clicked Twice!");
}
Debug.Log(timesPressed);
}