Confusion in IEnumerators and the difference between return and yield return

In the following code, Sam uses a return instead of a yield return.

public IEnumerator FadeOut(float time)
        {
            return Fade(1, time);
        }

        public IEnumerator FadeIn(float time)
        {
            return Fade(0, time);
        }

I understand that an IEnumerator must have at least one yield return statement. Is that correct?
Also, if we used yield return instead of return, how would that change the behavior of our fader?
I guess it makes sense to yield return Fade() as it is in our best interest to wait for Fade() to finish.

Because we’re returning a Coroutine, we can use return instead of yield return. We don’t need to yield because Fade will be doing the yielding for us. It’s a fine distinction, and in virtually any other case you would have to use a yield return.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms