LayerMask in unity code example
Example 1: collider layer = to layermask unity
layermask == (layermask | (1 << layer))
Example 2: unity get layermask
int layer = (int)Mathf.Log(uninteractablePartsLayer.value, 2);
Debug.Log("uninteractablePartsLayer "+LayerMask.LayerToName(layer));
Example 3: layermask in unity
} void FixedUpdate()
{
Transform transform = Camera.main.transform; if (Input.GetKeyUp("space"))
{
LayerMask mask = LayerMask.GetMask("Wall");
if (Physics.Raycast(transform.position, transform.forward, 20.0f, mask))
{
Debug.Log("Fired and hit a wall");
}
}
}
}