Help Can't find the Correct Parameters

So I am trying to use a raycast hit and a layermask apparently this just does not bode well with unity Here is the line:

if(Physics.Raycast(transform.position, transform.forward, Mathf.Infinity, hit, LayerM))

Here is the error:

BCE0023: No appropriate version of ‘UnityEngine.Physics.Raycast’ for the argument list ‘(UnityEngine.Vector3, UnityEngine.Vector3, float, UnityEngine.RaycastHit, UnityEngine.LayerMask)’ was found.

I understand that it is because I am not using the correct parameters but… what parameters can I use?

The problem is with your LayerM. Raycast uses an ‘int’, and you are passing a LayerMask. You can use LayerMask.value:

if(Physics.Raycast(transform.position, transform.forward, Mathf.Infinity, hit, LayerM.value))