private IEnumerator FadeCoroutine(float fromAlpha, float toAlpha, OnFadeCompleted callback, float fadeSpeed) { Color temp; float progress = 0f; while (progress < 1f) { LerpImageAlphaColor(fromAlpha, toAlpha, progress); yield return(new WaitForEndOfFrame()); progress += (Time.unscaledDeltaTime * fadeSpeed) / 100f; } // Ensures that the image is completed faded at the end. LerpImageAlphaColor(fromAlpha, toAlpha, 1); callback?.Invoke(); yield return(null); #region Local_Function void LerpImageAlphaColor(float a, float b, float t) { temp = imageToFade.color; temp.a = Mathf.Lerp(a, b, t); imageToFade.color = temp; } #endregion }
public static void FireOnFadeCompleted(String fadedObjectName) { OnFadeCompleted?.Invoke(fadedObjectName); }