【发布时间】:2018-04-06 01:30:04
【问题描述】:
我试图为我的启动画面制作一个乒乓球彩色文本。我试图只更改 alpha 值并且我的颜色在运行时变成黑色。当试图在函数中分配颜色时,它变成了白色。你们能告诉我我做错了什么以及我应该如何正确设置颜色吗?
using UnityEngine;
using UnityEngine.UI;
public class LerpAlpha : MonoBehaviour {
public float duration;
float alpha;
Text colorText;
Color textColor;
void LerpAlphaText()
{
float lerp = Mathf.PingPong(Time.time, duration) / duration;
alpha = Mathf.Lerp(0.0f, 1.0f, Mathf.SmoothStep(0.0f, 1.0f, lerp));
textColor.a = alpha;
///Also tried textColor = new Color(113, 75, 2, alpha); resulting in
///the white text
colorText.color = textColor;
}
void Start()
{
colorText = GetComponent<Text>();
}
void Update ()
{
LerpAlphaText();
}
}
【问题讨论】: