using UnityEngine;
using UnityEngine.Events;

public class Checkpoint : MonoBehaviour
{
    public static Checkpoint Active {  get; private set; }

    [SerializeField] private bool _isDefault;
    [SerializeField] private UnityEvent _onActivated;
    [SerializeField] private UnityEvent _onDisable;

    public void Activate()
    {
        if (Active)
            Active.Disable();

        Active = this;
        _onActivated?.Invoke();
    }

    public void Disable()
    {
        if (Active == this)
        {
            Active = null;
            _onDisable?.Invoke();
        }
    }

    void Awake()
    {
        if (_isDefault)
            Activate();
    }
}
