unity check collider layer code example
Example 1: unity check collider layer
function OnCollisionEnter(collision : Collision)
{
if (collision.collider.gameObject.layer == LayerMask.NameToLayer("LAYER_NAME"))
{
Debug.Log("Touched a rail");
}
}
Example 2: checking a gamobjects layer
if(gameObject.layer == LayerMask.NameToLayer("LAYER_NAME")){}