Beispiel #1
0
    private IEnumerator FadeCoroutine(float startAlpha, float endAlpha)
    {
        float currentAlpha = startAlpha;

        while (Mathf.Abs(currentAlpha - startAlpha) < Mathf.Abs(startAlpha - endAlpha))
        {
            fader.color   = GetFaderColorWithAlpha(currentAlpha);
            currentAlpha += fadeSpeed * Time.deltaTime * Mathf.Sign(endAlpha - startAlpha);
            yield return(null);
        }

        OnFadingComplete?.Invoke();

        yield return(null);
    }
Beispiel #2
0
    private IEnumerator FadeAlphaCoroutine(float startAlpha, float endAlpha, Image image)
    {
        float currentAlpha = image.color.a;

        while (Mathf.Abs(currentAlpha - startAlpha) < Mathf.Abs(startAlpha - endAlpha))
        {
            image.color   = new Color(image.color.r, image.color.g, image.color.b, currentAlpha);
            currentAlpha += fadeSpeed * Time.deltaTime * Mathf.Sign(endAlpha - startAlpha);
            yield return(null);
        }

        image.color = new Color(image.color.r, image.color.g, image.color.b, endAlpha);
        OnFadingComplete?.Invoke();

        yield return(null);
    }