How to use multiple layer masks with a box cast.

How can I make it so the raycast can detect 2 layers instead of 1?

public LayerMask collisionLayerMask;

RaycastHit2D raycastHit = Physics2D.BoxCast(bc2D.bounds.center, bc2D.bounds.size, 0f, Vector2.down, extraHeightTest + extraHeightTest, collisionLayerMask);

The difference between Layers vs LayerMasks:

“There are 10 types of people in this world: those who understand binary, and those who don’t.”

In your inspector, for the collisionLayerMask var your created, you can selected multiple Layers in that dropdown :slight_smile: it’ll then only apply to those Layers.

3 Likes