DOTween: Hiệu ứng mờ dần cho UI (DOFade)
C# Code
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
// Gắn script này vào một GameObject có component Image
[RequireComponent(typeof(Image))]
public class DoTweenFadeUI : MonoBehaviour
{
private Image uiImage;
public float endValue = 0f; // Fade out (0 = trong suốt, 1 = rõ nét)
public float duration = 1f;
void Awake()
{
uiImage = GetComponent<Image>();
}
void Start()
{
// Làm mờ Image đến giá trị endValue
uiImage.DOFade(endValue, duration).SetLoops(-1, LoopType.Yoyo);
}
}Sử dụng DOTween để làm mờ dần (fade in/out) một thành phần UI như Image hoặc TextMeshProUGUI.