Open Door blocks ShootAction

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)

1 Like

Nice. You could also have enable/disable the colliders.

1 Like

Yup both approaches work, either change the layer or just enable/disable the collider. I would go with the collider method since it’s so simple.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms