我试图在 1 秒内在两种颜色之间转换,从黑色到蓝色,但我似乎无法正确处理。目前,当我单击按钮时,颜色保持黑色并且永远不会变为蓝色。我需要解决什么问题?谢谢!
private Color startColor = Color.black;
private Color endColor = new Color(0.0f, 0.71f, 1.0f, 1.0f);
private float duration = 1.0F;
void OnButtonClick ()
{
AppData.SelectedPageConfig = Page ;
AnalyticsWrapper.CustomEvent ("SelectPicture", new Dictionary<string, object> {
{ "PictureName", Page.name }
}) ;
StartCoroutine(DoChangeColor());
StartCoroutine(DoChangeSceneDelay());
}
IEnumerator DoChangeColor()
{
float lerp = Mathf.PingPong(Time.deltaTime, duration) / duration;
transform.Find("Creature Color Crop").transform.Find("Creature Image").GetComponent<Image>().color = Color.Lerp(startColor, endColor, lerp);
yield return new WaitForEndOfFrame();
}
IEnumerator DoChangeSceneDelay()
{
yield return new WaitForSeconds(2);
SceneManager.LoadScene("ColoringBook_ColoringScreen");
}