- Home /
How to add layer to layer mask?
I don't quite understand how to work with bitmasks or layer masks yet, so... How to add one layer to layer mask? For instance I've got public LayerMask and assigned some layers through inspector. Now I want to cast Physics2D.OverlapAreaAll, with that LayerMask, but add one extra layer to it.
Comment
Best Answer
Answer by Cherno · Nov 24, 2015 at 10:09 PM
yourLayerMask |= (1 << LayerMask.NameToLayer("Default"));
yourLayerMask |= (1 << LayerMask.NameToLayer("AnotherLayer"));
yourLayerMask |= (1 << LayerMask.NameToLayer("Water"));
Thanks! Can you please tell me, will new mask work as intended if I'll add layer, which already presented in mask?
I don't know what happens if you try to add a layer to the mask which already has it, but I don't think it would cause any errors. It probably just gets ignored. Why don't you try it out? :)