Raycasts

I’m trying to get an object to point toward the nearest object under the mouse. This is what I have for code right now…

function Update () {
	var hit : RaycastHit;
	if (Physics.Raycast (Input.mousePosition,Input.mousePosition,hit)) {
		transform.LookAt (hit.point);
	}
}

I’m guessing I’m not even close…

Try this:

function Update ()
{
     var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     var hit : RaycastHit = new RaycastHit ();
     if (Physics.Raycast (ray, hit))
          transform.LookAt (hit.point);
}