title: C#, Unity - List<> (Argument is out of range...)
body: <p>I am making a simple spawn script. I have problem because I wanted to make dynamic array, and I stopped.</p>
  
  <p>The problem is I have now this error:</p>
  
  <blockquote>
    <p>ArgumentOutOfRangeException: Argument is out of range. Parameter name:
    index
    System.Collections.Generic.List`1[UnityEngine.GameObject].CheckIndex (Int32 index) ...</p>
  </blockquote>
  
  <p>code:</p>
  
  
  
  <pre><code>public float spawnTime = 5f;
  public float spawnDelay = 1f;      
  public int enemyID = 0;
  
  public List&lt;GameObject&gt; enemy = new List&lt;GameObject&gt;();
  
  // Use this for initialization
  void Start() {
      InvokeRepeating("Spawn", spawnDelay, spawnTime);
  }
  
  void Spawn ()
  {
      Debug.Log (enemyID);
      enemy[enemyID] = Instantiate (Resources.Load ("Enemies/Enemy"), new Vector3 (0, 3, 0), Quaternion.identity) as GameObject; // this is a problematic line, exactly this -&gt; enemy[enemyID]
      enemyID++;
  }
  </code></pre>