반응형
if((mask & (1 << layer)) != 0){
//포함됨
}
else{
//포함 안됨
}
LayerMask와 Layer는 모두 integer로 저장됨.
Unity는 32개까지의 레이어를 지원하고, integer는 32 bits.
(mask & (1 << layer)) != 0
위 식의 의미는, 특정 Layer가 LayerMask에 포함되는지 확인하려고 할때
1을 그 Layer의 위치로 shift연산을 하여 LayerMask의 해당 위치에 1이 존재하는지 체크
How Do LayerMasks Work?
LayerMasks are stored as an integer, but represent any combination of Layers in your game. Layers are also integers... so how does that work?
Unity only supports up to 32 layers. An integer is 32 bits. A LayerMask simply allocates one bit for each layer, where 0 means that layer is not included, and 1 means that it is.
반응형
'개발메모 > Unity' 카테고리의 다른 글
URP(Universal Render Pipeline)에서 Post-processing 하는 법 (0) | 2024.01.22 |
---|---|
Cinemachine 범위 정하기 (0) | 2023.11.06 |
3D 카메라(Perpendicular Projection)에서 ScreenToWorldPoint() 가 Input.mousePosition을 제대로 잡지 못하는 이유 (0) | 2023.10.23 |
Unpack vs Unpack Completely (0) | 2023.09.13 |
OnTriggerEnter2D 함수가 동작하지 않는 이유 (0) | 2023.08.07 |