Skip to main content

TriggerContainEvents

A class in Root.Township, the global namespace.

Fires an event when the first collider enters its trigger and another when the last one leaves, with an optional layer filter.

Constructors​

MemberWhat it is
TriggerContainEvents()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private HashSet<Collider> containedCollidersColliders currently inside the trigger.
private bool hasLayerFilterWhether layerFilter is applied.
private LayerMask layerFilterLayers that count. Empty means every layer.
private UnityEvent onEmptyEvent fired when the last collider leaves.
private UnityEvent onEnterEvent fired when the first collider enters.

Methods​

4 private and internal methods
MemberWhat it is
private void Awake()Turns the layer filter on only if a mask is set.
private void OnDisable()Clears the contained colliders and fires onEmpty if any were inside.
private void OnTriggerEnter(Collider other)Adds a matching collider and fires onEnter if it is the first one.
private void OnTriggerExit(Collider other)Removes a matching collider and fires onEmpty if none are left.