How to use raycast when standing still.

I made a script that shoots a raycast through the Mouse point to hit a collider. The problem is that it only will contact the collider if my player is moving.
function Start () {
}

function Update () {
	Screen.lockCursor = true;
	if(Input.GetKey("l")){
		Screen.lockCursor = false;
	}
	if(Input.GetMouseButtonDown(0)){
		//Debug.Log("LEFT SWAGGER LOL");
		
		var hit : RaycastHit;
		var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		
		if(Physics.Raycast(ray,hit,20.0)){
			//print("ERMEHGERD YOU HIT SOMETHING");
			if(hit.collider.tag == "Tree"){
					Debug.Log("Tree Hit");
					hit.collider.transform.GetComponent(scriptTree).hitCount();
				}
				else
				{
					Debug.Log("Nothing");
				}
			}
		}

}

I think it has something to do with the Screen.lockCursor, but Im not sure. Thank you for your help!

If you are using Screen.lockCursor while playing in the Unity Editor, left mouse click breaks this. Then there are all sorts of problems with Input.mousePosition after that. If you are using Screen.lockCursor, then it would be safe to assume you always expect the mouse to be in the center of the screen. Try this :

var ray : Ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );

Your ray will then always be cast from the center of the screen, even when Screen.lockCursor breaks in the editor (and webplayer!).