Layer masks are bitmasks that describe which layers are active or otherwise.
Active layers in the mask will be hit by the query.
A layer mask may be an int, but it doesn't represent a single layer.
Incorrectint layerMask = 5;
Incorrectint layerMask = LayerMask.NameToLayer("Name");NameToLayer returns a layer index, not a bitmask.Correctly create a layer mask:
Serialize a LayerMaskIf bitmasks are confusing, a simple option is to serialize a LayerMask and configure it via the Inspector.
public LayerMask ExampleMask;LayerMask can be passed to physics functions as it's implicitly convertible to int.
Double-check the mask value set in the inspector.
Or
Use LayerMask.GetMaskInitialise and use a mask created using LayerMask.GetMask.
Or
Use bit shiftingManually create a mask from layer indices using bit shifting.
Then pass that mask to the correct parameter of the query.