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