So this is my code, it generates a matrix of cells (blocks)
the types are:
private Transform[,] field;
private myCell[] cellMap;
private int[,] fieldMap;
public myCell[] cells;
the code is:
counter = 0;
for ( int i = 0; i < width; i ++ ) {
for ( int j = 0; j < height; j ++ ) {
int id = fieldMap[i,j];
cellMap[counter] = cells[id];
cellMap[counter].transform = ((Transform)Instantiate( cellMap[counter].transform, field[i,j].position, Quaternion.Euler(90,Random.Range(0,4) * 90,0)));
Destroy (field[i,j].gameObject);
cellMap[counter].transform.name = counter + "";
cellMap[counter].transform.rotation = Quaternion.Euler(cells[id].rotation + new Vector3(0, Random.Range (0,4) * 90, 0));
cellMap[counter].transform.tag = Tags.Cell;
cellMap[counter].transform.parent = transform;
counter++;
}
}
so now cellMap should contain a update list of ALL transforms generated, but it doesnt…
when i call this:
for ( int i = 0; i < cellMap.Length; i ++ ) {
Destroy( cellMap[i].transform.gameObject );
}
it destroys the last few blocks (few random blocks with id ~220, the amount if 225)