private IEnumerator Fade(float alphaFrom, float alphaTo, float durationInSeconds, float delayInSeconds, Action onFadeComplete)
{
isFading = true;
// delay
yield return new WaitForSeconds(delayInSeconds);
if (canvasGroup != null)
{
float progress = 0.0f;
// fade
while (progress <= 1.0f)
{
progress = progress + (Time.deltaTime / durationInSeconds);
canvasGroup.alpha = Mathf.Lerp(alphaFrom, alphaTo, progress);
yield return null;
}
// callback
if (onFadeComplete != null)
{
onFadeComplete.Invoke();
}
}
isFading = false;
}