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.

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.

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);

}