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);
}

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:

Thank you,
Unfortunately I have no idea how to implement it to my code :frowning: