title: Nested For Loops - generating a catan-style hex-grid in Unity
body: <p>As the title suggests, I am trying to generate a procedural hex grid in Unity using C#.</p>
  
  <pre><code>void Start () 
  {
      //5 mid
       startRowSize = 5;
  
      for (int i = 0; i &lt; startRowSize; i++)
      {
          GameObject newHex = (GameObject)Instantiate(hex);
          hexWidth = newHex.gameObject.renderer.bounds.size.z;
          newHex.transform.Rotate(new Vector3(0,30,0));
          newHex.transform.position = new Vector3((i * hexWidth),0,0);
      }
  
      for (int row = 0; row &lt;= startRowSize-1; row ++)
      {
      for (int i = 0; i &lt; row; i++)
      {
          GameObject newHex = (GameObject)Instantiate(hex);
          newHex.transform.Rotate(new Vector3(0,30,0));
          newHex.transform.position = new Vector3(((i*hexWidth)+((hexWidth/2))+(row*(hexWidth/2))),0,((startRowSize-row))*-(hexWidth/1.17f));
      }
      }
  }
  </code></pre>
  
  <p>The code works, however the rows are being generated "backwards", meaning the outer rows contain the higher amounts of hexes, while the inner rows contain the smallest.</p>
  
  <p>This is obviously the opposite effect that I am trying to achieve. I've been messing with this code for hours and I can't figure out why.</p>
  
  <p>Any thoughts?</p>