After following this lecture, my fader is stuck as soon as i play my game, resulting in a blank white screen.
My Fader.cs file looks like this:
using System.Collections;
using UnityEngine;
namespace GoL.SceneManagement
{
public class Fader : MonoBehaviour
{
CanvasGroup _canvasGroup;
Coroutine _currentActiveFade = null;
private void Awake()
{
_canvasGroup = GetComponent<CanvasGroup>();
}
public void FadeOutImmediate()
{
_canvasGroup.alpha = 1;
}
public IEnumerator FadeOut(float time)
{
return Fade(1, time);
}
public IEnumerator FadeIn(float time)
{
return Fade(0, time);
}
public IEnumerator Fade (float target, float time)
{
if (_currentActiveFade != null)
{
StopCoroutine(_currentActiveFade);
}
_currentActiveFade = StartCoroutine(FadeRoutine(target, time));
yield return _currentActiveFade;
}
private IEnumerator FadeRoutine(float target, float time)
{
while (Mathf.Approximately(_canvasGroup.alpha, target))
{
_canvasGroup.alpha = Mathf.MoveTowards(_canvasGroup.alpha, target, Time.deltaTime / time);
yield return null;
}
}
}
}
I’m using Unity version 2020.3.20f1.
Thanks in advance!