How to toggle gameObject collision

I have a Gameobject with collision that I’m attempting to turn on and off on input of touch/mouse button.

I would like there to be a delay before the collision is re-enabled.

Ideally I don’t want to destroy the game object just toggle its collision.

By no means am I a coder but trying to learn and attempted to give it a go. Unfortunately it doesn’t seem to be working but I think I’m close! Could you please have a look at my script to see where I have gone wrong.

Many thanks!

#pragma strict

function Start (){
	
}

function Update (){
collider.enabled = true;}

 if(Input.GetMouseButtonUp(0) ||  (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended))
{
	collider.enabled = false;
	Wait();
}

function Wait (){
	yield WaitForSeconds (2);
}

#pragma strict

function Update ()
{
	print(collider.enabled);
	if(Input.GetMouseButtonUp(0) ||  (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended))
	{
    	collider.enabled = false;
    	Wait();
	}
}
	
function Wait()
{
	yield WaitForSeconds (2);
	collider.enabled = true;
}

Thank you for your help. That has worked!