how to check gameobject layer 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 check collider layer
function OnCollisionEnter(collision : Collision)
{
if (collision.collider.gameObject.layer == LayerMask.NameToLayer("LAYER_NAME"))
{
Debug.Log("Touched a rail");
}
}