Application.LoadLevel with FadeOut

I’m testing some 3D GUIs with a oculus rift rig. And I was looking for a fadein/out script for the cameras. I found one script: Fade-in works great, but Fadeout doesn’t work. I’m using triggers to load a new level. In this case the screen freezes and just loads the new level. Is there a way to use fade in general for all triggers / levels?
Here’s the Screen-Fader script (it uses 2 boxes to block both camera-vision):

using UnityEngine;
using System.Collections;

public class Screenfader_level0 : MonoBehaviour {
		public float fadeSpeed = 1.5f;          // Speed that the screen fades to and from black.
		private bool sceneStarting = true;      // Whether or not the scene is still fading in.
		void Awake ()
			// Set the texture so that it is the the size of the screen and covers it.
			guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
		void Update ()
			// If the scene is starting...
				// ... call the StartScene function.
		void FadeToClear ()
			// Lerp the colour of the texture between itself and transparent.
			guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime);
		void FadeToBlack ()
			// Lerp the colour of the texture between itself and black.
			guiTexture.color = Color.Lerp(guiTexture.color,, fadeSpeed * Time.deltaTime);
		void StartScene ()
			// Fade the texture to clear.
			// If the texture is almost clear...
			if(guiTexture.color.a <= 0.05f)
				// ... set the colour to clear and disable the GUITexture.
				guiTexture.color = Color.clear;
				guiTexture.enabled = false;
				// The scene is no longer starting.
				sceneStarting = false;
		public void EndScene ()
			// Make sure the texture is enabled.
			guiTexture.enabled = true;
			// Start fading towards black.
			// If the screen is almost black...
			if(guiTexture.color.a >= 0.95f)
				// ... reload the level.

Like Jeff said your script will be wiped out when the new level is loaded. All you need is to out this line in your Awake function:


Keep in mind that this will make the gameobject including all attached scripts and child objects to survive the level change. So when the level is loaded this object will be still there. In your case when you reload the same scene and the scene already contains that script you will end up with two instances and you get a new one each time you reload the scene.

I’ve written a little helper script some time ago that does all this out of the box. The script doesn’t need to be attached to anything manually.

Thx, DestroyOnLoad works fine.

Bunny83: I have tried your global script. But I’m getting an error message for my levelselection script: Unknown identifier: ‘AutoFade’.
I have added AutoFade to my 3D Scene.