ro-webgl/Assets/Src/Utils/ButtonTriggerAnimation.cs
2021-12-21 09:40:39 +08:00

38 lines
873 B
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
[RequireComponent(typeof(Button))]
public class ButtonTriggerAnimation : MonoBehaviour
{
public Animator tagetAnimator;
public string animationName;
Button button;
// Start is called before the first frame update
void Start()
{
if (tagetAnimator == null) return;
button = GetComponent<Button>();
if (button == null) return;
button.onClick.AddListener(OnClickPlayAnimation);
}
public void OnClickPlayAnimation()
{
// tagetAnimator.CrossFade(animationName, 0.2f);
}
private void OnDestroy()
{
if (button == null) return;
button.onClick.RemoveListener(OnClickPlayAnimation);
}
}