Raycasting out from a first person controller

As I posted before I was trying to get OnMouseOver to do this for me but it wasnt happening, after looking into Raycasting I still cant get it to work. I want the raycast to tell me if the crosshair (GUI Crosshair at centre screen, locked to mouse position) is both pointing at and the player is close enough to an object, the intention is for this to then tell another script whether it should work (if statement checking the boolean of the ray) and also turn the crosshair another colour.

The issue I am having is getting the Ray to follow the camera on the First Person Controller. The public GameObject has been set to the main camera. The Debug is showing the ray stationary at a point away from the camera.

Please be aware I have no programming experience bar a couple of previous very simple scripts I did last week.

Here is how far I got with the Raycasting script.

public class CrosshairRay : MonoBehaviour 
{
	public float interactionDistance = 3f;
	public bool imnear;
	public GameObject cam;
	
	void Update ()
	{

	RaycastHit hit;
		Ray pointer = new Ray(cam.transform.localPosition, Vector3.forward);
		
		Debug.DrawRay(cam.transform.localPosition, Vector3.forward * interactionDistance);
		
		
		if(Physics.Raycast (pointer, out hit, interactionDistance))
			{
				if(hit.collider.tag == "Clickable")
				{
					imnear = true;
				}
				else
				{
					imnear = false;
				}
					
			}	
	}	
	
}

You want ‘cam.transform.position’. If the camera does not have a parent, ‘localPosition’ will always be (0,0,0). Also you may want the direction to be ‘cam.transform.forward’ instead of ‘Vector3.forward’. ‘Vector3.forward’ will work if the camera rotation is (0,0,0), but cam.transform.forward will work no matter what the rotation of the camera. Also, if this script is attached to the camera, there is no need of the ‘cam’ game object variable. And there is a form of Physics.Raycast() that takes a position and direction, so there is no need to build a Ray. Putting the changes together:

public class CrosshairRay : MonoBehaviour  {
    public float interactionDistance = 3f;
    public bool imnear;
	
    void Update () {
		RaycastHit hit;

		Debug.DrawRay(transform.position, transform.forward * interactionDistance);

		if(Physics.Raycast (transform.position, transform.forward, out hit, interactionDistance)) {
			imnear = (hit.collider.tag == "Clickable");
		}    
	}  
}