- Home /
Im trying to remove my account.
Unity how to make different enemy spawn one at a time
im trying to make it so when an enemy spawn a different enemy will spawn in that same spot but the next enemy will be faster it's like wave's if you beat the first enemy the next one will be faster and the next one will be even more faster all you have to do is jump over the enemy. the enemy will come down a path towards the player and the player will jump over the enemy and then the once the enemy die's the next enemy will spawn it a random system that will randomly choose the next enemy and get increase speed
Answer by sparkzbarca · Mar 10, 2015 at 06:36 PM
so your going to want to create a public array of gameobjects of the size you need and then fill the array in the editor with your prefabs you have created of enemies so.
int NumOfEnemies
Public Gameobject Enemies[NumOfEnemies];
then use random.range to get a number from 0 to number of enemies - 1
int RandomChoice = Random.Range(0,NumOfEnemies - 1);
now you have a random number to select from the list so you pick an enemy at random.
now you want to progressively increase the speed at which they spawn.
you can use Random.Range again and progressively increase the min to choose a speed for a object if you want it to go generally faster.
You can use invoke to delay the time and increase the number each time
bool NOTRUNNING = true;
void Update()
{
if(NOTRUNNING)
Invoke("SpawnEnemies");
}
void SpawnEnemies()
{
NOTRUNNING = True;
Instantiate(prefab, Vector3.zero, Quaternion.identity);
Yield.waitforseconds(SpawnSpeed);
NOTRUNNING = false;
}