【发布时间】:2021-09-03 07:42:44
【问题描述】:
我尝试使用 LeanTween,现在编写了自己的协程,但它们都不起作用。目标是让 TextMeshPro 元素的文本在一段时间内淡入/淡出,这应该足够简单,但显然不是。这是协程:
private IEnumerator FadeText(float target, float duration) {
Color color = text.color;
float timer = 0f;
float alpha = color.a;
while(timer < duration) {
timer += Time.deltaTime;
print($"{timer / duration}% is: {Mathf.Lerp(alpha, target, timer / duration)}");
color.a = Mathf.Lerp(alpha, target, timer / duration);
text.color = color;
yield return new WaitForEndOfFrame();
}
}
Debug.Log 显示正确的值(在所需的持续时间内从 0 到 255,反之亦然),但文本只是弹出。这是上面代码的样子(再次:使用 LeanTween 有相同的结果) : Example
文本“upgrades”应该在 5 秒内淡出,在 0.4 秒内淡出。
我错过了什么吗?
【问题讨论】: