ButtonTriggerAnimation.cs 836 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. [System.Serializable]
  7. [RequireComponent(typeof(Button))]
  8. public class ButtonTriggerAnimation : MonoBehaviour
  9. {
  10. public Animator tagetAnimator;
  11. public string animationName;
  12. Button button;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. if (tagetAnimator == null) return;
  17. button = GetComponent<Button>();
  18. if (button == null) return;
  19. button.onClick.AddListener(OnClickPlayAnimation);
  20. }
  21. public void OnClickPlayAnimation()
  22. {
  23. // tagetAnimator.CrossFade(animationName, 0.2f);
  24. }
  25. private void OnDestroy()
  26. {
  27. if (button == null) return;
  28. button.onClick.RemoveListener(OnClickPlayAnimation);
  29. }
  30. }