Hi for some reason even after changing the duration the fader flashes for a second when going itno play mode.
I think it maybe being cancelled out or something upon the second initial load, unless that only happens when going into the portal.
Anyway here is my code:
In saving wrapper:
private IEnumerator LoadLastScene()
{
yield return _savingSystem.LoadLastScene(defaultSaveFile);
Fader fader = FindObjectOfType<Fader>();
fader.FadeOutImmediately();
yield return fader.FadeIn(_fadeInTime);
}
I’ve tried changing the fade in time, in both the script and the inspector, but it doesn’t make a difference.
This is my relevant code in the fader:
public IEnumerator FadeIn(float time)
{
float fadeInValue = 0;
return Fade(fadeInValue, time);
}
public IEnumerator Fade(float target, float time)
{
if (_currentActiveFade != null)
{
StopCoroutine(_currentActiveFade);
}
_currentActiveFade = StartCoroutine(FadeRoutine(target, time));
yield return _currentActiveFade;
}
IEnumerator FadeRoutine(float target, float time)
{
while (Mathf.Approximately(_canvasGroup.alpha, target) != true)
{
_canvasGroup.alpha = Mathf.MoveTowards(_canvasGroup.alpha, target, Time.deltaTime / time);
yield return null;
}
}
}
Edit: I just completed the next lecture which changes the code to:
public Coroutine FadeIn(float time)
{
float fadeInValue = 0;
return Fade(fadeInValue, time);
}
public Coroutine Fade(float target, float time)
{
if (_currentActiveFade != null)
{
StopCoroutine(_currentActiveFade);
}
_currentActiveFade = StartCoroutine(FadeRoutine(target, time));
return _currentActiveFade;
}
IEnumerator FadeRoutine(float target, float time)
{
while (Mathf.Approximately(_canvasGroup.alpha, target) != true)
{
_canvasGroup.alpha = Mathf.MoveTowards(_canvasGroup.alpha, target, Time.deltaTime / time);
yield return null;
}
}
}
Which fixed the issue, how has changing the return types to coroutines fixed this?