How to stop a script after a counter?

What I am trying to do is I am making a tower defense game and I want my spawn script to stop after my counter reaches a number. This is what I have so far.

//creat time and set to 3 second
public float interval = 3.0f;
float timeleft = 0.0f;

// Human game object to spawn
public GameObject Human = null;	

public int counter = 0;



// Update is called once per frame
void Update () {
	
	
	
	//time left untill next spawn
	timeleft -=Time.deltaTime;		
	if (timeleft <= 0.0f)
	{
		counter ++;
		//spawn human
		GameObject enemy = (GameObject)Instantiate(Human, transform.position, Quaternion.AngleAxis(-90, Vector3.left));
					
		
		//reset time
		timeleft = interval;
		
		if(counter == 3)
		{
			
		}

I just cant figure out how to make the script stop after it the counter reaches 3. please help.

Three ways come to mind:

If you’re never going to access the spawner again, destroy it:

//Destroy() removes an object from the scene
if (counter == 3) GameObject.Destroy(this);

If you might use it again, but want it to stop updating for a bit:

//disabled components don't get Update() calls
if (counter == 3) enabled = false;

Or, you could keep getting Update() calls, but change the script’s behavior once the counter reaches a particular point:

void Update() {

    ....

    if (counter < 3) {
        //do spawning stuff
    } else {
        //do not spawning stuff
    }
}

You could also use Invoke() to call a function in X seconds, or InvokeRepeating() to call a function every X seconds. Less code, but also a touch less flexible depending on what exactly you’re trying to do.