IndexOutOfRangeException: Array index is out of range.

Hi! I’m getting this error and i have no idea of what it is and why im getting it.
It’s saying that the problem is on line 24
Here is my tilemap class

using UnityEngine;
using System.Collections;

public class TileMap : MonoBehaviour {
	public TileType[] tiletypes;

	int[,] tiles;

	int mapSizeX = 10;
	int mapSizeY = 10;

	void Start () {
		GenerateMapData ();
		GenerateMapVisual();
	}

	void GenerateMapData(){
		//Allocate our map tiles
		tiles = new int[mapSizeX,mapSizeY];
		
		//Initialize all of our map tiles to be grass
		for (int x = 0; x < mapSizeX; x++) {		
			for (int y = 0; x < mapSizeY; y++) {
				tiles[x,y] = 0;
			}
		}
		//Make a big swamp area
		for (int x = 3; x < 5; x++) {		
			for (int y = 0; x < 4; y++) {
				tiles[x,y] = 1;
			}
		}
		
		// a U-shaped mountain range
		tiles[4,4] = 2;
		tiles[5,4] = 2;
		tiles[6,4] = 2;
		tiles[7,4] = 2;
		tiles[8,4] = 2;
		
		tiles[8,5] = 2;
		tiles[8,6] = 2;
		
		tiles[4,5] = 2;
		tiles[4,6] = 2;
	}
	
	void GenerateMapVisual(){
		for (int x = 0; x < mapSizeX; x++) {		
			for (int y = 0; x < mapSizeY; y++) {
				TileType tt = tiletypes[ tiles[x,y] ];				
				Instantiate(tt.tileVisualPrefab,new Vector3(x, y, 0), Quaternion.identity);
			
			}
			
		}
	}

}

And here is my tile type class

using UnityEngine;
using System.Collections;

[System.Serializable]
public class TileType {

	public string name;

	public GameObject tileVisualPrefab;

}

Thanks in advance!:smiley:

line 23

for (int y = 0; x < mapSizeY; y++) {

should be

for (int y = 0; y < mapSizeY; y++) {

Also lines 29 and 50 should probably be changed as well.

thanks dude! :wink: