Raycasts hitting the crosshair

How could I make it so that raycasts always hit my crosshair in the middle of the screen? The script is on my gun which is to the right of me, so the raycast goes to the right.

var damage : float = 5;


function Update () {
	var direction = transform.TransformDirection(Vector3.left);
	var hit : RaycastHit;
	var localOffset = transform.position;
	
	if(Input.GetButtonDown("Fire1")){
		if (Physics.Raycast (localOffset, direction, hit, 400)) {
			Debug.DrawLine (localOffset, hit.point, Color.cyan);
			print("we have fired!");
			hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
		}
	}
}

Look at camera.ScreenPointToRay( screenPixelPos ); for getting a good ray for the raycast. That gives you a straight down the screen ray.

I think you’d be better off ignoring the gun position for aiming, and just doing a straight raycast right down the center of the screen. You could then draw a line or something from the gun to the target, for effect.

Otherwise, you get a diagonal raycast (with respect to the screen) and the crosshair will only be correct for one paticular distance.