# How to move an object composed by different cubes?

Hi, my problem is: how to move an object composed by different cubes (Think about the Tetris pieces) dragging one of these cubes and move all the cubes.

My script is:

``````
static var dragging : boolean = false;
var posizione : Vector3;
var mousex : float = 0.0;
var mousey : float = 0.0;

function OnMouseDown()
{
dragging = true;
}

function OnMouseUp()
{
dragging = false;
}

function Update()
{
if(trascinamento.dragging)
{
mousex = 0.5*Input.GetAxis("Mouse X");
mousey = 0.5*Input.GetAxis("Mouse Y");
transform.position.x += mousex;
if((transform.position.y + mousey) >= 1)
transform.position.y += mousey;
}
}

``````

I've duplicated the original cube and I've created my object composed by multiple cubes, the problem is: they don't move togheter! How to solve it?

Thanks

make an empty gameObject and put your cubes as childs of it(drag and drop then on top of the gameObject). Then when you move the parent, all the children move too.

an example on drag and drop feature (not my authoring) : sorry for no indentation, i`ll fix it later, kinda in a hurry now

`

# pragma downcast

// Attach this script to an orthographic camera. var spinSpeed = 60;

private var obj : Transform; // The object we will move. private var offSet : Vector3; // The object's position relative to the mouse position.

function Update () { var ray = camera.ScreenPointToRay(Input.mousePosition); // Gets the mouse position in the form of a ray. if (Input.GetMouseButtonDown(0)) { // If we click the mouse... var hit : RaycastHit; if (Physics.Raycast(ray, hit, Mathf.Infinity)) { // Then see if an object is beneath us using raycasting. if( hit.transform.gameObject.tag !=("Imovel")){ obj = hit.transform; // If we hit an object then hold on to the object. offSet = obj.position-ray.origin; // This is so when you click on an object its center does not align with mouse position.

``````         if (obj.rigidbody) {
obj.rigidbody.isKinematic = true;
}
}
}

``````

} else if (Input.GetMouseButtonUp(0) && (obj) !=null) { if (obj.rigidbody) { obj.rigidbody.isKinematic = false; }

```  obj = null;      // Let go of the object.
````

} if (obj) { obj.position = Vector3(ray.origin.x+offSet.x, ray.origin.y+offSet.y, 0); // Only move the object on a 2D plane. if (Input.GetButton("Fire2")) { obj.Rotate(0, spinSpeed*Time.deltaTime, 0); } } }

I've created an empty gameObject and I've put all the cubes like children of the new empty gameObject but what about the scripts? I've tried to put the script on the new Object but any cube move.. thanks..