Hey guys, I am trying to make a tile map for a board game. I have two scripts to generate the map that I thought would work.
The first script is on an empty object
SOOO… that script works just fine. When I play the game a row of (mapsize) length tiles are generated. BUT, this next script is where I have trouble.
This script I place on the Tile prefab…
Now, this script should have created a line of (maplength) length cubes along the y axis of every cube. But, here is my problem.
The cubes infinitely generate along the y axis, because EVERY tile has that script on it… I guess I need to ditch the second script and make the GameManager generate y axis and x axis cubes. But, in order to do that, I would need to name the instantiated cubes along the x axis in the first loop, right? and then for each cube generated along the x axis, make a row of y axis cubes branch off of it.
sigh… I am bad at explaining this, if you need more info please ask. How would I do this?
How would I generate cubes in an x axis line using a loop, name those generated cubes, and then generate more cubes along the y axis of every named cube from the first loop?
but an example would be as follows: assuming you are using the naming convention of TileX-Y
#pragma strict
var maplength = 10;
var mapWidth = 10;
public var Tile : Transform;
function Start () {
for(var y : int = 0; y < mapWidth; y++){
for(var x : int = 0; x < maplength; x++){//nested within Y loop
var curTile:Transform = Instantiate(Tile, Vector3(x * 1.0, y*1.0, 0), Quaternion.identity);
curTile.name = "Tile"+x+"-"+y;
}
}
}