using System.Collections; using System.Collections.Generic; using UnityEngine; public class DetectionZone : MonoBehaviour { public string tagTarget = "Player"; public static bool ableToOpen = false; // When object is detected, it is added to the list of actively detected objects public List detectedObjs = new List(); // Detect when object enters range void OnTriggerEnter2D(Collider2D collider) { if(collider.gameObject.tag == tagTarget) { ableToOpen = true; detectedObjs.Add(collider); } } // Detect when object leaves range void OnTriggerExit2D(Collider2D collider) { if(collider.gameObject.tag == tagTarget) { detectedObjs.Remove(collider); } if(detectedObjs.Count == 0) { ableToOpen = false; } } }