I have 35 Tile objects and I'm trying to put them into a 2D array (and list) but I keep getting an IndexOutofRange error when populating the array. The code I'm using is:
private Tile[,] AllTiles = new Tile[5,7];
private List<Tile> EmptyTiles = new List<Tile>();
// Use this for initialization
void Start () {
Tile[] AllTilesOneDim = GameObject.FindObjectsOfType<Tile> ();
foreach (Tile t in AllTilesOneDim) {
// Fill 2D Array AllTiles
AllTiles [t.indRow, t.indCol] = t;
// Fill List with all tiles
EmptyTiles.Add (t);
}
}
I should note that each Tile object contains an int for indRow between 0-4 and an int for indCol between 0-6.