How to get the mouse direction while left click is pressed?

Hi again guys.

I’ve stumbled a bit in the code and I’ve had over 8 hours of trying to get this today but I couldn’t get to the end of it. I’ve searched all over and found similar questions but none offered me a good response honestly.

I want to click on an object and while holding the click to know if my mouse is moving up, down, left or right so that afterwards I could perform actions based on these 4 directions.

I’ve tried to debug it like this, but it doesn’t quite get me there. Any help would be greatly appreciated (even a link towards a question that has been answered if this is a dupe):

function Update()
{
	if(Input.GetMouseButtonDown(0))
	{
	OnMouseDrag();
	}
}

function OnMouseDrag(){

	if(Input.GetAxis("Mouse X") > 0)
	{
		Debug.Log("X e mai mare ca 0");
	}
	
	if(Input.GetAxis("Mouse X") < 0)
	{
		Debug.Log("X mai mic ca 0");
	}
	
	if(Input.GetAxis("Mouse Y") > 0)
	{
		Debug.Log("y mare ca 0");
	}
	
	if(Input.GetAxis("Mouse Y") < 0)
	{
		Debug.Log("y mic ca 0");
	}
}

Here is one solution using Vector3.Dot(). There are efficiency improvements that can be made:

#pragma strict

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;
}