Find a space between gameObject and mouse position (or two ray points)

Hi, I’m trying to make a system where clicking and dragging will tell you the distance between the point where you initally clicked, and the current position (updating as you drag it). My initial idea was to have it so that the gameObject froze when clicked, and then use Vector3.Distance to get the distance between the gameObject and ScreenToWorldPoint- however, I since tried a different way by setting the variable of two ray hits (the second being continuous), code shown below. I get the error below (presumably vector3.distance isn’t the way to do this?).

> BCE0017: The best overload for the method ‘UnityEngine.Vector3.Distance(UnityEngine.Vector3, UnityEngine.Vector3)’ is not compatible with the argument list ‘(UnityEngine.Ray, UnityEngine.Ray)’.

    function Update()
    {	
	
	var initialMousePos:Ray;
	var currentMousePos:Ray;
	
	
	//Get first position on click
	if (Input.GetMouseButtonDown(0)) {
	 initialMousePos = Camera.main.ScreenPointToRay(Input.mousePosition);
	}
	
	//Get second position on hold-down mouse
	if(Input.GetMouseButton(0)) {
     	currentMousePos = Camera.main.ScreenPointToRay(Input.mousePosition);
 		var distance = Vector3.Distance(initialMousePos, currentMousePos);
 		print(distance);
    }

I would also really love to get the rotation direction between the two positions. (guessing this will come by getting the + or - of each axis from the distance variable)

Any solution or suggestion is greatly appreciated, thanks!

Why don’t you just spawn another gameobject on Input.GetMouseButtonUp(0)?
Also it’s not working because you’re setting the var initialMousePos and currentMousePos to Rays, not Vector3 positions. Also you want to use ScreenToWorldPoint instead of ScreenPointToRay.

var initialMousePos : Vector3;
var currentMousePos: Vector3;
if (Input.GetMouseButtonDown(0)) {
    initialMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
if (Input.GetMouseButtonUp(0)) {
    currentMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    var distance = Vector3.Distance(initialMousePos, currentMousePos);
    print(distance);
}