Unity camera settings CullingMask

There are a fixed 32 layers in Unity. Setting CullingMask can be understood as assigning a 32-length binary number. 0 means off and 1 means on.

All closed: 0 (all are 0 so all are closed, 000000...0000)

Turn on all: -1 or ~0 (reverse, equivalent to all being 1, 111111...1111)

Only open the third one: 1<<2 (the default is in the 1st position, and then moved two places to the left,...000100, because it is moved to the left, so two 0s are added to the right of 1)

Open the 1st, 3rd and 4th: 1|1<<2|1<<3 can also be written as 1 + (1 << 2) + (1 << 3)

Open except the first one: ~1 (000...0001 becomes 111...1110)

Open except the 3rd one: ~(1<<2)

Accumulate the third one on the original basis: Camera.main.cullingMask |= 1 << 2

Remove the third one on the original basis: Camera.main.cullingMask &= ~(1 << 2)

Multiplication means: 111...111*111...011, which is equivalent to changing the third digit to 0, so the third digit is removed.

Note: The index of an uncertain level can be viewed in the Project Setting to avoid writing errors.

おすすめ

転載: blog.csdn.net/u010197227/article/details/128534254