I set the door to the Obstacle layer so units cannot shoot through a closed door, but when opening the door the small part of the door left tends to block a diagonal shooting raycast, so I also change the layer programatically to Default for the door prefab and its children:
in OpenDoor()
and CloseDoor()
:
Transform rootTransform = transform;
transform.gameObject.layer = LayerMask.NameToLayer( "Obstacles" );
SetAllChildTransformsToLayer( rootTransform, "Obstacles" );
SetAllChildTransformsToLayer is the same children looping as before but taking a layermask as an argument
private void SetAllChildTransformsToLayer( Transform root, string layerName)