raycast error in unity

hi i was just wandering if anyone else has had this problem before i send a report of to unity…

basically everytime i try to use rays i get an error in my game and isnt fixed until i start a new scene this is what i get

NullReferenceException
UnityEngine.Camera.ScreenPointToRay (Vector3 position)
drawRay.Update () (at Assets/drawRay.js:31)

anyone had this before when using rays

function Update (){
if (Input.GetMouseButtonDown(0)){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
}
if (Physics.Raycast (ray, hit)) {
Debug.Log(" You just hit " + hit.collider.gameObject.name);
}
}
}

ok it seems that the issue is fixed by tagging the camera as main camera, maybe having two different cameras in the scene or something messes with unity. thanks for the help[.