using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class Button3D : MonoBehaviour, IPointerDownHandler
{
    [SerializeField] PointerEventData.InputButton MouseButton;
    [SerializeField] Animator Animator;
    [SerializeField] string AnimationTrigger = "ButtonPressed";
    [Space]
    [SerializeField] UnityEvent Action;

    public void OnPointerDown(PointerEventData eventData)
    {
        if (eventData.button != MouseButton) return;

        Action?.Invoke();

        if (Animator == null) return;
        Animator.ResetTrigger(AnimationTrigger);
        Animator.SetTrigger(AnimationTrigger);
    }
}
