How to get the layer id from a layer mask?
I'm using a layer mask with two layers for a raycast.
I select which via the editor and then combine them in Start:
public LayerMask groundLayer;
public LayerMask selectableLayer;
LayerMask mask;
void Start () {
mask = groundLayer | selectableLayer;
}
Then I use mask
for the raycast.
The problem arises when I try to compare what layer the raycast hit:
RaycastHit hitInfo;
bool hit = Physics.Raycast(Cam.ScreenPointToRay(Input.mousePosition), out hitInfo, 200, mask);
if (hit)
{
Debug.Log(hitInfo.transform.gameObject.layer);
Debug.Log(groundLayer.value);
Debug.Log(selectableLayer.value);
if (hitInfo.transform.gameObject.layer == selectableLayer.value)
{
}
else if (hitInfo.transform.gameObject.layer == groundLayer.value)
{
}
}
In the layer editor, Ground layer is 8, Selectable layer is 9. But if I hit the ground with the raycast the console output is:
8
256
512
What is up with 256 and 512? How do I compare the layer from the hit with the layers in the editor?
Comment