function OnCollisionEnter(collision : Collision) { if (collision.collider.gameObject.layer == LayerMask.NameToLayer("LAYER_NAME")) { Debug.Log("Touched a rail"); } }