Physics.Raycast() is a HORRIBLY overloaded function. I recommend ALWAYS specifying the named arguments rather than hoping you got them in the correct order.
This is because layerMask (an int) and maxDistance (a float) can be easily mistaken at the call site if you are passing an integer value for maxDistance. In this case, no error will be returned, and it will just fail mysteriously.
The time you save by typing out named arguments will be your own.
Instead of this:
Physics.Raycast(origin.position, transform.forward, out hit, layerMask)
ALWAYS do this:
Physics.Raycast(
origin: origin.position,
direction: transform.forward,
hitInfo: out hit,
layerMask: layerMask)
This will also reveal instantly if you have asked for a permutation of arguments that is not matched by the available overloads.
EDIT: the same goes for constructing Ray()
and Plane()
objects: the identical-typed arguments can easily be inadvertently swapped, leading to mass confusion, especially when they sort of work near (0,0,0) for instance.