title: Spawning waves of enemies Unity3D
body: <p>I'm developing a game in which I want to spawn waves of enemies. In each wave of enemies, I spawn from a different Spawn Point. For exemple, I have 6 Spawn Points, the first wave of enemies spawn from the 4th point, the second wave spawns from the 1st point, etc.</p>
  
  <p>I wrote a code that let me spawn waves of enemies but my problem is that it spawn the waves of enemies from all the 6 spawn points in the first wave of enemies.</p>
  
  <p>When i click on play, I have waves of enemies from the 6 spawn points not from one spawn point for each wave.</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class Waves : MonoBehaviour
   {
   public GameObject Enemy = null;
  
   public int hazardCount = 3;
   public float spawnWait=0.5f;
   public float startWait=1;
   public float waveWait=4;            
   public Transform[] spawnPoints; 
  
   void Start ()
   {
       StartCoroutine(SpawnWaves ());
   }
  
   IEnumerator SpawnWaves ()
   {
       yield return new WaitForSeconds (startWait);
       while (true)
       {
           for (int i = 0; i &lt; hazardCount; i++)
           {
               int spawnPointIndex = Random.Range (0, spawnPoints.Length);
  
               Instantiate (Enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
  
               yield return new WaitForSeconds (spawnWait);
           }
           yield return new WaitForSeconds (waveWait);
       }
   }
   }
  </code></pre>