Last active
January 19, 2017 04:45
-
-
Save wuqxuan/b54ba7af267be8bbd4da6e2e68919f7f to your computer and use it in GitHub Desktop.
Get the mouse direction while left click is pressed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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