Answer the question
In order to leave comments, you need to log in
How to set the sequence and time of appearance of enemies?
I have 3 prefabs (enemies), each one has an "Enemy" script attached with their behavior, the number of lives and their speed are configured in the prefabs themselves.
public class Enemy : MonoBehaviour{
public float MaxLife;
public float speed;
..........
}
public class Spawner : MonoBehaviour{
public GameObject enemy1;
public GameObject enemy2;
public GameObject enemy3;
public float spawnTime = 3f;
public float startSpawnTime = 0f;
private float timer =0;
void Update(){
timer -= Time.deltaTime;
startSpawnTime += Time.deltaTime;
if(timer <= 0 ){
if(startSpawnTime > 0f && startSpawnTime < 9f) Instantiate(enemy1, transform.position, transform.rotation);
else if(startSpawnTime > 9f && startSpawnTime < 18f) Instantiate(enemy2, transform.position, transform.rotation);
else if(startSpawnTime > 18f && startSpawnTime < 30f) Instantiate(enemy3, transform.position, transform.rotation);
timer = spawnTime;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question