mouse drag detection

How might I detect when the mouse first begins to drag as oppose it already dragging?

(I hope that made sense)

I can detect that the mouse is dragging by checking original position to current position. But I need to detect when it starts to drag from stop as well.

2 Answers

2

private var imBeingDragged : boolean = false;

function OnMouseDrag () {

if (!imBeingDragged) {

    //Do something here

    imBeingDragged = true;

}

}

function OnMouseUp () {

imBeingDragged = false;

}

function Update ()

{

	print (imBeingDragged);

}

Input.GetMouseButtonDown will tell you when the user first clicks the mouse, which you can use to set the original position. Dragging stops when Input.GetMouseButtonUp is true.

If you know when the dragging starts, and you can detect whether you happen to be over an object that moves, start the appropriate behavior. On Input.GetMouseButtonDown == true, check to see whether there is a moving object Input.mousePosition, if there is then move that object, if not, use your selection box.