using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(BoxCollider2D))] public sealed class Sensor2DProbe : MonoBehaviour { [SerializeField] private LayerMask actorLayers = ~0; private readonly HashSet countedActors = new HashSet(); private void OnTriggerEnter2D(Collider2D other) { if (!isActiveAndEnabled) return; if ((actorLayers.value & (1 << other.gameObject.layer)) == 0) return; Rigidbody2D body = other.attachedRigidbody; GameObject actor = body != null ? body.gameObject : other.gameObject; if (countedActors.Add(actor.GetInstanceID())) Debug.Log("Unique 2D actors: " + countedActors.Count, this); } }