Help With Add and Remove on a loop

Hi I’m pretty new to scripting, and have got pretty stuck. I’m basically trying to add and remove an object on a loop with a 4 second delay in between. Any help would be awsome. p.s Turning the render on and off wont work, as the collider is still there.

Disabling the GameObject itself with SetActive will disable all the components on it, including the collider. You can use a float subtracted by Time.deltaTime per-frame in the Update function to behave like a timer.

public GameObject go;
float delay = 4.0f;
float timer = 4.0f;

void Update(){
    timer -= Time.deltaTime;
    if(timer <= 0f){
        timer = delay;
        go.SetActive(!go.activeSelf);
    }
}

Note that you have to do this from a different object because all components will be disabled, it will not continue to execute.

this ended up working for me , with desired result.

var delay : float = 8.0;
var timer : float = 8.0;
var thePrefab : GameObject;

  
function Update(){
	timer -= Time.deltaTime;

if(timer <= 0){

	timer = delay;
	var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
	Destroy(gameObject.Find("Cube1(Clone)"), 4);
}

}