unity get layer by name code example
Example 1: unity get layer of gameobject
// This will retrun the layer mask of the specified gameObject
gameObject.layer
// You can as well modify this value through code
gameObject.layer = LayerMask.NameToLayer("SomeOtherLayer")
Example 2: unity get layermask
int layer = (int)Mathf.Log(uninteractablePartsLayer.value, 2);
Debug.Log("uninteractablePartsLayer "+LayerMask.LayerToName(layer));
Example 3: unity find layer by name
using UnityEngine;public class Example : MonoBehaviour
{
void Start()
{
Debug.Log(LayerMask.NameToLayer("TransparentFX"));
}
}