Exemplo n.º 1
0
    public void FadeGraphicToColor(Color color, float fadeSpeed = 1f, OnGraphicFaded callback = null)
    {
        StopCoroutineIfExists();

        fadeCoroutine = StartCoroutine(FadeGraphicToColorCoroutine(color, fadeSpeed, callback));

        #region Local_Function

        void StopCoroutineIfExists()
        {
            if (fadeCoroutine != null)
            {
                StopCoroutine(fadeCoroutine);
            }
        }

        #endregion
    }
Exemplo n.º 2
0
    private IEnumerator FadeGraphicToColorCoroutine(Color color, float fadeSpeed, OnGraphicFaded callback)
    {
        Color start = objGraphic.color;

        float progress = 0f;

        while (progress < 1f)
        {
            objGraphic.color = Color.Lerp(start, color, progress);

            progress += Time.deltaTime * fadeSpeed;
            yield return(new WaitForEndOfFrame());
        }

        objGraphic.color = color;

        callback?.Invoke();
        yield return(null);
    }