I'm trying to transition between two colors, black to blue over a 1 second period but I can't seem to get it right. Currently when I click the button the color stays black and never transitions to blue. What do I need to fix? Thank you!
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");
}