RayCast Rotation

Hi guys. I watched brackey new tutorial on raycast but I cant get the raycast to rotate with the camera.

public float fireRate;
public float damage;
public float range;
public Camera fpsCam;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Fire1")) 
{
Shoot ();
}
Debug.DrawRay (transform.position, Vector3.forward, Color.green);
}
public void Shoot()
{
RaycastHit hit;

if (Physics.Raycast (transform.position,Vector3.forward,out hit, range)) 
{
Debug.Log (hit.transform.name);
}
}

I cant help myself because I teach programming to myself and the scriping API hasn’t helped.

I assume the script you already put on the camera.
you shouldn’t use “Vector3.forward” on line 22,
instead you should use transform.forward therefore the vector will alway point to current transform forward.

or may be you can try this asset
Raycast plugin