TextFadeLoop.cs 925 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public class TextFadeLoop : MonoBehaviour
  6. {
  7. public TextMesh[] uiText; // 拖入你的 Text 组件
  8. public float duration = 1f;
  9. public float targetScale = 0.8f;
  10. void Start()
  11. {
  12. // 初始颜色设置(可选)
  13. Color startColor = uiText[0].color;
  14. startColor.a = 1f;
  15. foreach (var item in uiText)
  16. {
  17. item.color = startColor;
  18. // 执行透明度循环
  19. //item.DOFade(0f, duration) // 变透明
  20. // .SetLoops(-1, LoopType.Yoyo) // 无限循环,Yoyo表示往返
  21. // .SetEase(Ease.InOutSine); // 平滑过渡
  22. item.transform.DOScale(targetScale, duration)
  23. .SetLoops(-1, LoopType.Yoyo)
  24. .SetEase(Ease.InOutSine);
  25. }
  26. }
  27. }