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.
int layerMask = 5;
Correctly create a layer mask:
LayerMask
If 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
LayerMask.GetMask
Initialise and use a mask created using LayerMask.GetMask
.
Or
Manually create a mask from layer indices using bit shifting.
Then pass that mask to the correct parameter of the query.