hey!
well this might help - I found some excellent tile based tutorials for flash…and I think it would be great to have this stuff translated into Unity compatible ideas.
Heres the tutorial Im attempting to go thru and re-jig around.
Ive gotten to generating the map array like this:
// build myMapArray
myMapArray = new Array (
[1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,1,1],
[1,0,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1]);
I then pass this array into
a map building function ( not done yet!! watch the sloppy code! )
like this:
BuildMap(myMapArray);
and notice all the casting I had to do because Im tripping up on the strict typing rules…?
// Instantiates a prefab in a grid
function BuildMap (map : Array) {
print("The map: " + map);
var mapWidth : int;
var mapHeight : int;
mapWidth = map.length;
print("The array width: " + mapWidth);
mapHeight = (Array(map[0]).length); // whats up with this casting? doesnt map[0].length just return an int?
print("The map height: " + mapHeight);
for (var y = -(mapHeight); y < mapHeight; y++) {
for (var x= -(mapWidth);x<mapWidth;x++) {
var pos = Vector3 (x, 0, y) * spacing;
var newCube : GameObject = Instantiate(cube0, pos, Quaternion.identity);
newCube.transform.parent = GameObject.Find("Tiles").transform;
}
}
}