using UnityEngine;
using UnityEngine.Events;

public class FadeTrigger : MonoBehaviour
{
    public GameObject linkedGate;
    public UnityEvent inEvent;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            SwitchGateState(gameObject, linkedGate);
            inEvent.Invoke();
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            inEvent.Invoke();
        }
    }

    private void SwitchGateState(GameObject gateToTurnOff, GameObject gateToTurnOn)
    {
        gateToTurnOff.gameObject.SetActive(false);
        gateToTurnOn.gameObject.SetActive(true);
    }
}
