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

public class UnityEvents : MonoBehaviour
{
    public enum Mode { OnEnable, OnTrigger };
    public Mode mode;
    public UnityEvent events;

    private void OnEnable()
    {
        if (mode == Mode.OnEnable)
        {
            ExecuteEvents();
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (mode == Mode.OnTrigger)
        {
            ExecuteEvents();
        }
    }

    private void ExecuteEvents()
    {
        if (events != null)
        {
            events.Invoke();
        }
        gameObject.SetActive(false);
    }
}
