What is wrong with my script

Spawn game object called polly, make it a child of the empty game object it spawned on. then when the bullet hits it it dies and another spawns.

The problem is that when the bullet hits polly another polly spawns INSTANTLY. I would like for the object to not be there for a few seconds then spawn. The script that handles the destroying and collision works fine.

Thanks

var polly : GameObject;
var chil  = 0;
var alive : boolean = false;

function Update () {
chil = transform.childCount;
Check();

}

function Check(){
if(alive == false){
var ins : GameObject = Instantiate(polly, transform.position, transform.rotation);
ins.transform.parent = transform;
alive = true;

}

if(transform.childCount <= 0){
Debug.Log("dead");
alive = false;	
}
}

You each frame check if the GameObject is alive, and if not you instantiate it. Your polly will be dead 1 frame, and alive the next.

What you want to do is set a timer to affect the delay .

Something like this :

    ...
    var DelayTimeBetweenSpawns = 2.5;
    var TimeSinceDeath =0.0;
    ..

    function Check()
    {
      ...
      if (alive == false && TimeSinceDeath>DelayTimeBetweenSpawns)
      {
        // reinstantiate
      }
      else 
      {
        TimeSinceDeath+=Time.deltaTime;
      }
    }
    if (transform.childCount<=0 && alive )
    {
      alive=false;
      TimeSinceDeath=0.0;
    }
    }

Please note that I didn’t compile this and I code in C# , so some errors might slipped in.