Search Unity

problem with coroutine not executing code

Discussion in 'Animation' started by Dacotahslim, Jan 21, 2021.

  1. Dacotahslim

    Dacotahslim

    Joined:
    Nov 27, 2020
    Posts:
    24
    I have a black image over the screen. When conditions are met, the animation changes the transparency from transparent to solid, creating a fade-out effect. This works fine and displays the "a" values changing from 0 to 1. But after fading out, the code to change scenes is not activated until "faded" is displayed over 100 times. Basically, it fades, then gets stuck there for a few seconds before the scene actually changes. Why is it displaying "Faded" so many times but not firing off the scene change?

    if (isDead && isGrounded)
    {
    StartCoroutine(Fading());
    }

    IEnumerator Fading()
    {
    Debug.Log(black.color.a);
    anim.SetBool("Fade", true);
    yield return new WaitUntil(() => black.color.a >.9);
    Debug.Log("faded");
    SceneManager.LoadScene("LevelFail");

    }