I'm trying to do a basic random tile map to generate a space background. At a certain point, when I need to generate more of the map I increase the size of the map and then I want to iterate over the whole map and set tiles on all new spaces.
int oldHeight = map.height;
int oldWidth = map.width;
int newHeight = (map.height *= 2);
int newWidth = (map.width *= 2);
print (oldHeight + " " + oldWidth);
print (map.height + " " + map.width);
int tileCount = map.data.tilePrefabs.Length;
map.Build();
int a;
for(int i = 0; i < map.height - 1; i++) {
a = 0;
for(int z = 0; z < map.width - 1; z++) {
print (a);
a++;
if(map.GetTile(i,z,0) < 0)
map.SetTile(i,z,0,Random.Range(0,tileCount));
}
}
map.Build();
That code has some of the debugging stuff in it, but you should see the process.
Anyway, the problem I'm having is that GetTile throws an array out of bounds exception whenever I get past a value of 64 on the x/y coordinate of the tile. I'm not entirely sure why this is happening and more importantly how I can fix it. Since I've reset the height of the map shouldn't this not be a problem?