How to changed the center position of child gameObjects / pivot of parent? (Updated)

I am dynamically generating 6 columns and rows of cubes in a loop as children of a gameObject and then setting their transform to parent so I can rotate , move or scale the parent and the children will all move as well. This starts the cube 1 at 0,0 and increments position by cube.x + cube.width. When rotating, this will mean the cubes are moved along the left edge (0,0). I want to make the generated cubes sit at parent.width / 2 and parent.height / 2. Below is an image to demonstrate what I wish to do:-

alt text

Does Unity contain helper methods to adjust the center point of the parent so that the cubes can be moved / scaled on a central point? E.g. centerPoint.x = this.width / 2

Thanks

I'm not sure what you mean exactly, but whatever it is you're wanting to do, you should be able to accomplish it by manipulating the Transform.position and Transform.localPosition fields for the parent and child objects (either in the inspector or via scripting) as needed.

Have a look at the following script :

var parentGameObject: Transform;
var scale = 0.1; // scale of the cube
var gap = 0.01; // gap between the cubes

function Start()
{
    for(var i = 0; i<6; i++)
    {
        for(var j=0;j<6;j++)
        {
            var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.localScale= Vector3.one*scale;
            cube.transform.position = Vector3(-2.5*scale + (scale+gap)*j, 0, 2.5*scale+ (scale+gap)*i);
            cube.transform.parent = parentGameObject;
        }
    }
}