OneShotOneKill/Assets/Script/UGUI/Util/TextAlphaPingPong.cs

24 lines
821 B
C#
Raw Normal View History

2026-01-07 21:27:42 +00:00
using TMPro;
using UnityEngine;
public class TextAlphaPingPong : MonoBehaviour
{
public float speed = 1f; // 알파값 변화 속도
public float minAlpha = 0.2f; // 최소 알파값
public float maxAlpha = 1f; // 최대 알파값
TextMeshProUGUI textMeshPro; // TextMeshPro 텍스트 참조
private void Update()
{
if (DSUtil.CheckNull(textMeshPro))
textMeshPro = GetComponent<TextMeshProUGUI>();
// Mathf.PingPong을 사용하여 0과 1 사이에서 반복되는 값 생성
float alpha = Mathf.Lerp(minAlpha, maxAlpha, Mathf.PingPong(Time.time * speed, 1));
// 텍스트 색상에서 알파 채널만 업데이트
Color color = textMeshPro.color;
color.a = alpha;
textMeshPro.color = color;
}
}