C# and layer masking for Physics.Raycast()

How can I handle filtering out what I want Physics.Raycast() to collide with in C#? Ideally I would be able to give the name of the layer I want the raycast to hit and ignore all others.

It looks like what you’re asking about is covered here.

It kind of was, but wasn’t explained very well I didn’t think. I got this working and the key for me was:

LayerMask boardTiles = 1 << LayerMask.NameToLayer(“BoardColliders”);

Thanks

2 Likes