Draw a Ray to the Mouse Postion

I’m trying to draw a ray to the mouse position from my player but it is acting very strange. Firstly the whole ray isn’t even where the mouse is but if I use Debug.DrawLine instead of Debug.DrawRay then it works. Here is a screen shot of the first problem. The second problem is whenever I move the player the end point of the line also moves when it shouldn’t because the mouse isn’t actually moving, just the player. Here is the code:

var mouseWorldPosition;
var raycastHit : RaycastHit;

function Update(){
	DestroyTile();
}

function DestroyTile(){
	var mouseWorldPosition : Vector3 = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, 15));
	Debug.DrawRay(transform.position, mouseWorldPosition, Color.red);
}

Can someone please tell me why it’s acting so strangly?

Thanks.

var mouseWorldPosition : Vector3 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Debug.DrawLine(transform.position, mouseWorldPosition, Color.red);

Debug.DrawRay takes a direction as second parameter.

And ScreenToWorldPoint can use the mousePosition directly.

So, use Input.mousePosition directly, and not like you did (what are the 15 units in z direction thought to do?).