Click and drag an object

Hi,

Is there a simple way to click on an object and drag it somewhere else and then drop it there?

Thanks!! Chris

The Wiki has a script for dragging objects: http://www.unifycommunity.com/wiki/index.php?title=DragObject

To restrict movement on an axis, examine the line

var move = cam.ScreenToWorldPoint(Vector3(mousePos.x, mousePos.y, camTransform.position.y - myTransform.position.y)) - myTransform.position;

Below that, zero out the value that you don't want changed. For example, to ensure the object isn't dragged on the z-axis:

move.z = 0;

If you want the script to be more portable, I'd recommend adding a public variable at the beginning:

var dragMultipliers : Vector3 = Vector3.one;

In the inspector, change "Drag Multipliers" values to "0" on axes that shouldn't move. Then, where you would put `move.z = 0;`, instead put

move = move * dragMultipliers;

move = move * dragMultipliers;
(cannot be used with a left hand side of type ‘UnityEngine.Vector3’ and a right hand side of type ‘UnityEngine.Vector3’.
)

move = move * dragMultipliers;
( cannot be used with a left hand side of type ‘UnityEngine.Vector3’ and a right hand side of type ‘UnityEngine.Vector3’.
)