Layer Masking

Hey all. I’m trying to cast a ray for collision detection but I only want it to hit certain objects in my scene so I’m using a layer mask. However I want it to register things on only two layers (one is a render on top layer essentially).

So if my hit layer is 7 I know that the layer mask = 1<<7. However if I want both 7 and 8 lets say how do I do that? I don’t quite understand bitshifting. Is there a union operator or something? thanks.

The | operator should do the trick:

mask = (1<<7) | (1<<8);

A quick search on the forum works wonders :slight_smile:

http://forum.unity3d.com/viewtopic.php?t=1841&highlight=layermask