Hi all,
I have an object. On click and drag i should instantiate that object and make the instantiated object move along with the mouse cursor. I have the following code. I am attaching it only to the object. So only the main object is moving. But i want the instantiated object to move. Can anyone help me?
var newObject : Transform;
private var depth = 5;
function Update()
{
x = Input.mousePosition.x;
y = Input.mousePosition.y;
Debug.Log("x: "+x+"y: "+y);
}
function OnMouseDown()
{
Instantiate(newObject,transform.position,transform.rotation);
}
function OnMouseDrag()
{
transform.position = camera.main.ScreenToWorldPoint (Vector3 (x, y, depth));
}