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);
}
}
}