Respawn an enemy prefab after its destroyed

var respawn : Transform;
var dead : boolean = false;

function OnTriggerEnter(theCollision : Collider)
{
   if(theCollision.gameObject.name=="Spotlight") 
   {
     Destroy(gameObject);
     Debug.Log("Dead");
     dead = true;

   }
}


function Respawn()
{

	if(dead == true)
	{
		Instantiate(respawn, Vector3(0,0,0), Quaternion.identity);
	}

}

I’m having trouble getting my enemies to re-spawn, at the moment i have just the one enemy following me around. I’m trying to re-spawn his after he collides with my spotlight.

I have a prefab Enemy that i want to use to create more instances of Enemy once it gets destroyed.

I’m pretty sure my code above is destroying the prefab itself and thus cannot create any more instances but I’m not sure how to just destroy an instance of a prefab. The code above is attached to my enemy.

Id appreciate if anyone could help me out.

Updated:

The problem was that when you were destroying the gameobject it was destroying the spawning code together, that was in the same object.
Using a empty gameobject and spawning other gameobject will allow you to only destroy the enemy object.

Code:

var inmap : Transform; // This variable will store the spawned enemy
var respawn : Transform;
var dead : boolean = false;
 
function Start () 
{
    inmap = Instantiate(respawn, Vector3(0,0,0), Quaternion.identity); // Create the first enemy when the game starts
inmap.parent = transform; // Set it as child, so you can move it by moving the spawner
}
 
function OnTriggerEnter(theCollision : Collider)
{
   if(theCollision.gameObject.name=="Spotlight") 
   {
     Destroy(inmap); // Destroy the enemy object, but not the spawner (which have the code)
     Debug.Log("Dead");
     dead = true;
   }
}
 
function Respawn()
{
    if(dead == true)
    {
       inmap = Instantiate(respawn, Vector3(0,0,0), Quaternion.identity); // create another instance of the enemy
       inmap.parent = transform; // set the instance as child of the spawner
       dead = false; // prevents an infinite respawn
    }
}

===========
Old:

Try changing: function Respawn() to function Update()

If it works, the problem is that the Respawn function isn’t being called anywhere, even if dead is true, the function will not be executed.