I have an array of enemy prefabs inside which, I'm adding the different kinds of enemies I want it to spawn. Currently it spawns any enemy it wants to and there is no control over how many times I want a particular enemy to spawn. How do I make it so that a particular enemy spawns rarely ? Here is my current code:
public float spawnTime = 5f; // The amount of time between each spawn.
public float spawnDelay = 3f; // The amount of time before spawning starts.
public GameObject[] enemies; // Array of enemy prefabs.
void Start ()
{
// Start calling the Spawn function repeatedly after a delay .
InvokeRepeating("Spawn", spawnDelay, spawnTime);
}
void Spawn ()
{
// Instantiate a random enemy.
int enemyIndex = Random.Range(0, enemies.Length);
Instantiate(enemies[enemyIndex], transform.position, transform.rotation);
}
↧