I have a method that fades the screen to black, then fades away back again using coroutines but I couldn't get the 2nd part to work.
FadeToBlack()
works if I put yield return null
instead of yield return StartCoroutine(LightUp());
so I know that isn't the problem
private IEnumerator FadeToBlack()
{
for (float t = 0.01f; t < fadeOutTime; t += Time.deltaTime)
{
color = new Color(0, 0, 0, 1);
night.color = Color.Lerp(night.color, color, Mathf.Min(1, t / fadeOutTime));
yield return StartCoroutine(LightUp());
}}
If I put yield return StartCoroutine(LightUp());
in FadeToBlack instead of null it immediately turns black without the fading part. Here's what LightUp();
looks like
private IEnumerator LightUp() {
for (float t = 0.01f; t < fadeOutTime; t += Time.deltaTime)
{
color = new Color(0, 0, 0, 0);
Color colorD = new Color(0, 0, 0, 1);
night.color = Color.Lerp(colorD, color, Mathf.Min(1, t / fadeOutTime));
yield return null;
}
}