- Home /
Spawning enemies javascript
I have enemies spawning randomly in few positions. My problem is that sometimes when you kill one of them, another spawns in exactly same position without any delay at all, so when you think you have killed that enemy there is another at his place shooting at you.
Is there any way that I could delay spawn of enemy in position that I have just killed one?
function CreateMob() {
var randPosIndex: int = Random.Range(0, spawnPositions.Length);
var randMobIndex: int = Random.Range(0, enemies.Length);
var mobInst: GameObject = Instantiate(
enemies[randMobIndex],
Vector3(0, 0, 0),
Quaternion.identity);
var enemyBehaviour: EnemyBehaviour = mobInst.GetComponent(EnemyBehaviour);
enemyBehaviour.x = spawnPositions[randPosIndex].x;
enemyBehaviour.y = spawnPositions[randPosIndex].y;
enemyInstances.Push(mobInst);
enemyTimeouts.Push(enemyBehaviour.damageTimeout);
}
Answer by Kiloblargh · Apr 10, 2014 at 07:16 PM
You can change the way you pick a "random" position so it never picks the same position twice, or picks at least (n) different ones before it will pick the same one again.
Read this tutorial:
Answer by Bubeq · Apr 16, 2014 at 09:31 AM
Thank you, Unfortunately I have no idea how to implement it to my code :(
Your answer
Follow this Question
Related Questions
Multiple spawn location with random game object in random time spawn c# 1 Answer
Particle effect before spawn enemy 1 Answer
How to handle entity management 1 Answer
My wave system isn't working 0 Answers
Changing spawning position with C# 2 Answers