CameraFade.OnGUI C# (CSharp) Method

OnGUI() public method

public OnGUI ( ) : void
return void
    void OnGUI()
    {
        // If delay is over...
        if (Time.time > instance.m_FadeDelay)
        {
            // If the current color of the screen is not equal to the desired color: keep fading!
            if (instance.m_CurrentScreenOverlayColor != instance.m_TargetScreenOverlayColor)
            {
                // If the difference between the current alpha and the desired alpha is smaller than delta-alpha * deltaTime, then we're pretty much done fading:
                if (Mathf.Abs(instance.m_CurrentScreenOverlayColor.a - instance.m_TargetScreenOverlayColor.a) < Mathf.Abs(instance.m_DeltaColor.a) * Time.deltaTime)
                {
                    instance.m_CurrentScreenOverlayColor = instance.m_TargetScreenOverlayColor;
                    SetScreenOverlayColor(instance.m_CurrentScreenOverlayColor);
                    instance.m_DeltaColor = new Color(0, 0, 0, 0);

                    if (instance.m_OnFadeFinish != null)
                        instance.m_OnFadeFinish();

                    Die();
                }
                else
                {
                    // Fade!
                    SetScreenOverlayColor(instance.m_CurrentScreenOverlayColor + instance.m_DeltaColor * Time.deltaTime);
                }
            }
        }
        // Only draw the texture when the alpha value is greater than 0:
        if (m_CurrentScreenOverlayColor.a > 0)
        {
            GUI.depth = instance.m_FadeGUIDepth;
            GUI.Label(new Rect(-10, -10, Screen.width + 10, Screen.height + 10), instance.m_FadeTexture, instance.m_BackgroundStyle);
        }
    }