using UnityEngine; /// /// Attach this behavior to a master room collider. Enables everything in this room OnTriggerEnter of [tag] /// disables everything in this room OnTriggerExit of [tag] /// public class Optimizer : MonoBehaviour { [SerializeField] public string Tag; [SerializeField] private GameObject[] references; [SerializeField] private bool beginDisabled = true; private void Start() { if (beginDisabled) Disable(); } private void OnTriggerEnter(Collider other) { if (other.CompareTag(Tag)) Enable(); } private void OnTriggerExit(Collider other) { if (other.CompareTag(Tag)) Disable(); } public void Enable() { foreach (var go in references) go.SetActive(true); } public void Disable() { foreach (var go in references) go.SetActive(false); } }