How do I do an action for a certain amount of time?

In my maze game, I want to have the player be able to see the blocks you can pass through for only a certain amount of times and for a certain amount of time. There are blocks you can push through and i want to have the player press space and have those blocks turn red for 1 second and the player can only do this for 5 times

This is some code I use for something similar

(Sorry, I have not tested this, but something in this line should work)

public class PlayerMovement : MonoBehaviour
{
    public float Showtime = 0f;
    public int counter = 5;

    void Update ()
    {
      if (Input.GetKey(KeyCode.Space) && counter > 0)
      {
        Showtime = 5f;
        counter = counter - 1;
      }

      if (Showtime > 0f)
      {
        swingmotion = swingmotion - (Time.deltaTime);
        //Do your thing for 5 seconds.... change colour etc.        
      }  
    }
}