using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class TriggerZone : MonoBehaviour
{
    [SerializeField]
    private Triggerable linkedObj;
    [SerializeField]
    private bool onEnter = true, onStay = false, OnExit = false;
    public UnityEvent enterEvent;
    public UnityEvent stayEvent;
    public UnityEvent exitEvent;
    // Start is called before the first frame update
    private void OnTriggerEnter(Collider other) {
        if(!onEnter)return;
        if(other.gameObject.tag.Equals("Player")){
            linkedObj?.TriggerEvent(other);
            enterEvent?.Invoke();
        }
    }

    private void OnTriggerStay(Collider other) {
        if(!onStay)return;
        if(other.gameObject.tag.Equals("Player")){
            linkedObj?.TriggerEvent(other);
            stayEvent?.Invoke();
        }
    }

    private void OnTriggerExit(Collider other) {
        if(!OnExit)return;
        if(other.gameObject.tag.Equals("Player")){
            linkedObj?.TriggerEvent(other);
            exitEvent?.Invoke();
        }
    }
}
