using UnityEngine; using System; namespace Fruitomation.Game { public enum TriggerType { Enter, Stay, Exit } public class TriggerDetector : MonoBehaviour { private Action RegisteredActionStay; private Action RegisteredActionEnter; private Action RegisteredActionExit; public void SetAction(Action action, TriggerType type) { switch (type) { case TriggerType.Stay: RegisteredActionStay = action; return; case TriggerType.Enter: RegisteredActionEnter = action; return; case TriggerType.Exit: RegisteredActionExit = action; return; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } } private void OnTriggerEnter2D(Collider2D other) => RegisteredActionEnter?.Invoke(other); private void OnTriggerStay2D(Collider2D other) => RegisteredActionStay?.Invoke(other); private void OnTriggerExit2D(Collider2D other) => RegisteredActionExit?.Invoke(other); } }