Beispiel #1
0
        // Inspired by https://unity3d.com/learn/tutorials/projects/stealth/screen-fader

        /// <summary>
        /// Fades the screen to black, performs the given action, and then fades the scene back in.
        /// </summary>
        /// <param name="fadeSpeed">The lerp rate when fading.</param>
        /// <param name="onBlack">An action to perform when the screen is black, or <c>null</c> to
        /// perform no action.</param>
        public static void PerformScreenFadeInOut(float fadeSpeed, Action onBlack)
        {
            GameObject screenFader = new GameObject("ScreenFader");

            GUITexture guiTexture = screenFader.AddComponent <GUITexture>();

            guiTexture.color      = Color.clear;
            guiTexture.texture    = Texture2D.whiteTexture;
            guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);

            ScreenFaderScript script = screenFader.AddComponent <ScreenFaderScript>();

            Action onScriptClear = delegate() {
                GameObject.Destroy(screenFader);
            };

            Action onScriptBlack = delegate() {
                if (onBlack != null)
                {
                    onBlack();
                }

                script.FadeToClear(fadeSpeed, onScriptClear);
            };

            script.FadeToBlack(fadeSpeed, onScriptBlack);
        }
Beispiel #2
0
 public void FadeToBlack()
 {
     screenFaderScript.gameObject.SetActive(true);
     screenFaderScript.FadeToBlack();
 }