Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wuqxuan/b54ba7af267be8bbd4da6e2e68919f7f to your computer and use it in GitHub Desktop.
Save wuqxuan/b54ba7af267be8bbd4da6e2e68919f7f to your computer and use it in GitHub Desktop.
Get the mouse direction while left click is pressed
private var v3Pos : Vector3;
private var threshold = 9;
function OnMouseDown() {
v3Pos = Input.mousePosition;
}
function OnMouseDrag() {
var v3 = Input.mousePosition - v3Pos;
v3.Normalize();
var f = Vector3.Dot(v3, Vector3.up);
if (Vector3.Distance(v3Pos, Input.mousePosition) < threshold) {
Debug.Log("No movement");
return;
}
if (f >= 0.5) {
Debug.Log("Up");
}
else if (f <= -0.5) {
Debug.Log("Down");
}
else {
f = Vector3.Dot(v3, Vector3.right);
if (f >= 0.5) {
Debug.Log("Right");
}
else {
Debug.Log("Left");
}
}
// v3Pos = Input.mousePosition;
}
http://answers.unity3d.com/questions/452018/how-to-get-the-mouse-direction-while-left-click-is.ht
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment