2D Game Problem

Is there any way I can make this code that I’m using check twice if space bar was pressed.

 using UnityEngine;
    using System.Collections;
    
    public class ExampleClass : MonoBehaviour {
        void Update() {
            if (Input.GetKeyDown(KeyCode.Space))
                print("space key was pressed");
            
        }
    }

using UnityEngine;
using System.Collections;

 public class ExampleClass : MonoBehaviour {

     int counter;

     void Update() {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             print("space key was pressed");

             counter++;

             If(counter == 2)
              {
                 //Do what you want when space has been pressed twice

                  counter = 0; //reset counter
              }

        }       
     }
 }