using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class UIButtonToggle : MonoBehaviour
{
    public bool isPressed = false;
    public UnityEvent onPressed;
    public UnityEvent onReleased;
    void Awake()
    {
        Button button = GetComponent<Button>();
        if (button != null)
        {
            button.onClick.AddListener(
                () =>
                {
                    isPressed = !isPressed;
                    if (isPressed) onPressed?.Invoke();
                    else onReleased?.Invoke();
                });
        }
    }
}
