Once instantiated enemy is spawned and destryed none other will spawn.

I found a script online (well a few) and they all had the same problems, I assume it’s got something to do with when bullet collides with enemy, destroy enemy. But I changed that and it didn’t work.

var prefab : Transform;
var spawnPoint : Transform;

var spawnRate = 0.8;
private var lastSpawn=0.0;

function Update(){
	// error checking
	spawnRate=Mathf.Abs(spawnRate);
	if(spawnRate > 0.0){
		if(Time.time > lastSpawn + spawnRate){
			lastSpawn = Time.time;
			Instantiate (prefab, spawnPoint.position, spawnPoint.rotation);
		}
	}
}

The code looks fine to me, and works like a charm. But once I destroy a instantiated prefab none other will spawn, and that’s slightly annoying.

Any ideas?

EDIT:
Bullet Code:

    var bulletSpeed : int;
var power : float = 300;


function Update () {

//amount to view bullet
amtToMove = bulletSpeed * Time.deltaTime;

transform.Translate(Vector3.forward * amtToMove);

		rigidbody.AddForce(Vector3(0,0,power));


}


function OnBecameInvisible () {
  Destroy(gameObject);
}



function OnTriggerEnter(otherObject: Collider){

if(otherObject.gameObject.tag == "enemy1"){
	playerScript.playerScore +=50;
	Destroy(gameObject);
	}

if(otherObject.gameObject.tag == "enemy2"){
	playerScript.playerScore +=100;
	Destroy(gameObject);
	}
}

This code seems to be ok. There are three ways for it to not work:

1- spawnRate being modified by some other function or script to 0;

2- the spawnPoint object being destroyed by mistake instead of the enemy;

3- the prefab object being destroyed - it would only occur if it’s a scene object instead of a real prefab (sometimes I create the object, drag it to a prefab but inadvertenly use the object instead of the prefab to instantiate other clones)

i think you attached the script to the enemy itself or any other object that will be destroyed with your enemy.
create a gameObject and attach the spawner script to it and drag the enemy prefab from project view to it. also drag the spawnpoint object from your scene object to and and be careful to don’t destroy it.
however if the problem is losing references it will throw a null reference exception when trying to instantiate.

a similar code could be something like this. it’s more lightweight too.

function Creator ()
{
while (true)
{
Instantiate (enemy,enemypos.position,enemypos.rotation);
yield WaitForSeconds(spawnRate);
}
}

as you know variables for enemy and enemypos must be defined on top of the script but instead of Update i used coroutines.