CanvasBillboard.Fade C# (CSharp) Method

Fade() private method

Coroutine used to fade the billboard from one alpha value to another.
private Fade ( float alphaFrom, float alphaTo, float durationInSeconds, float delayInSeconds, Action onFadeComplete ) : IEnumerator
alphaFrom float
alphaTo float
durationInSeconds float
delayInSeconds float
onFadeComplete Action
return IEnumerator
    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;
    }