ImageBlinker.cs 541 B

123456789101112131415161718192021
  1. using DG.Tweening;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class ImageBlinker : MonoBehaviour
  5. {
  6. public float blinkDuration = 0.1f;
  7. private void OnEnable()
  8. {
  9. Image targetImage = transform.GetComponent<Image>();
  10. // 重置alpha值
  11. Color tempColor = targetImage.color;
  12. tempColor.a = 1f;
  13. targetImage.color = tempColor;
  14. // 执行闪烁动画
  15. targetImage.DOFade(0, blinkDuration).SetSpeedBased().SetLoops(-1, LoopType.Yoyo) .SetEase(Ease.InOutSine);
  16. }
  17. }