两种颜色之间的差异

我试图在两种颜色之间过渡,在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");

}

回答:

就像rotating或随着时间的推移移动GameObjecss,该XXXLerp功能仍然起作用的,同样的方式。值得一读的是,了解lerp是如何工作的。唯一需要改变的地方是Quaternion.LerpColor.Lerp

bool changingColor = false; 

IEnumerator lerpColor(Image targetImage, Color fromColor, Color toColor, float duration)

{

if (changingColor)

{

yield break;

}

changingColor = true;

float counter = 0;

while (counter < duration)

{

counter += Time.deltaTime;

float colorTime = counter/duration;

Debug.Log(colorTime);

//Change color

targetImage.color = Color.Lerp(fromColor, toColor, counter/duration);

//Wait for a frame

yield return null;

}

changingColor = false;

}

使用:

Image imageToLerp; 

void Start()

{

imageToLerp = transform.Find("Creature Color Crop").transform.Find("Creature Image").GetComponent<Image>();

StartCoroutine(lerpColor(imageToLerp, Color.black, Color.blue, 1f));

}

以上是 两种颜色之间的差异 的全部内容, 来源链接: utcz.com/qa/258127.html

回到顶部