How to make a ray always shoot forward from Camera viewpoint.

The Title is pretty much the question. Currently my Ray seems to shoot forward if I’m moving forward and backwards if i’m moving backwards. Here is what I currently have.

var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var hit : RaycastHit;
 if(Input.GetButton("Fire1") && Physics.Raycast (ray, hit, Range) && health > 1 && time > 0.25) {

//Shooting Code is here


I assume at some point it would be .forward but that doesn’t seem to be working.

Any help would be great.

Try something like this.

var hit : RaycastHit;
var foundHit : boolean = false;
foundHit = Physics.Raycast(transform.position, transform.forward, hit);
    if(foundHit && hit.distance <= 3 && Input.GetKeyDown(KeyCode.Fire1 && == "Enemy")) {
    	//hurt enemy