- Home /
Question by
IMTRIGGERHAPPY9 · Sep 13, 2011 at 05:29 AM ·
2dinstantiatearray
2D Array's
does anybody know how i would go about putting my instantiated objects into my array? cause i have no clue. with the normal javascript array you would just use .add, but with this one i have no clue how to put a transform into my array? help?
var instantiateObject : Transform;
var gridX = 10;
var gridY = 10;
function Start () {
//create two new arrays for the x and y axis
var map = new String[gridX,gridY];
for ( var x = 0; x < gridX; x++){
for (var y = 0; y < gridY; y++){
var myName = Instantiate(instantiateObject, Vector3(x *.5,0,y * .5), Quaternion.identity);
myName.name = "x: " + x + "y: " + y;
map = myName.name;
}
}
print(map[0,0]);
}
Comment
Best Answer
Answer by SilverTabby · Sep 13, 2011 at 05:47 AM
var myArray : Transform[,] = new Transform[5,5];
myArray[0,1] = this.transform;
for(var X : int = 0; X < myArray.Length(0); X++)
for(var Y: int = 0; Y < myArray.Length(1); Y++)
{
Debug.Log(myArray[X,Y].position);
}
That should be all the information you need to work with and loop through 2d arrays.
myArray.Length(0) gave me errors. myArray.GetLength(0) works.