Hi,
I have been reading a lot of “Answers” to this problem and none of them work - at all.
I have an Event like Start or Input event and I want that event to trigger a coroutine which will fade in an image. After the image is faded in I want it to fade out.
Sounds really simple, tried everything, can’t get it to work:
void Start ()
{
StartCoroutine ("EasterEgg");
}
//...
private IEnumerator EasterEgg()
{
yield return StartCoroutine("FadeIn");
//yield return new WaitForSeconds (2f); //tried this as an alternative solution, also didn't work (never executes second Coroutine
StartCoroutine ("FadeOut");
}
public IEnumerator FadeIn ()
{
SpriteRenderer logo = transform.FindChild("Logo").GetComponent<SpriteRenderer>();
while (logo.color.a < 255)
{
logo.color = new Color (logo.color.r, logo.color.g, logo.color.b, logo.color.a + 0.01f);
yield return null;
}
Debug.Log ("!!!I was here!"); //This NEVER gets printed
}
public IEnumerator FadeOut ()
{
SpriteRenderer logo = transform.FindChild("Logo").GetComponent<SpriteRenderer>();
while (logo.color.a > 0)
{
logo.color = new Color (logo.color.r, logo.color.g, logo.color.b, logo.color.a - 0.01f);
yield return null;
}
}
What it does:
- Fades the logo in,
… that was it… It doesn’t print anything, doesn’t fade it out nothing.
I would be REALLY glad if somebody could explain this to me, thanks.