Seppi
1
var enemyRate = 1.0;
var elf : Transform;
private var spawnEnemy = true;
function FixedUpdate () {
if(spawnEnemy){
Instantiate(elf,transform.position,transform.rotation);
StartCoroutine("SpawnEnemy", 0);
}
}
function SpawnEnemy () {
spawn = false;
yield WaitForSeconds(enemyRate);
spawn = true;
}
The enemys for some reason spawn extremely fast and are deleted almost immediately. Help?
roooob
2
Looks like you forgot the name of your boolean, in SpawnEnemy() you’re setting spawn to false/true instead of spawnEnemy!
A quick tip. It makes no sense to start each time in Update or FixedUpdate a Coroutine. You don’t need to leave the Coroutine:
function SpawnEnemy ()
{
while (true)
{
Instantiate(elf,transform.position,transform.rotation);
yield WaitForSeconds(enemyRate);
}
}
Start the SpawnEnemy method once with StartCoroutine. Thats all.