FadeInOut

Introduction
Author: PsychicParrot

Little script to fade an image (stretched to fit the screen, so use a 1x1 black pixel for a simple black fade in/out).

Simply apply it to your camera (or an empty GameObject), set the texture to use, set the fadeSpeed and call fadeIn or fadeOut

Easiest way is probably to apply this script to your main camera in the scene, then wherever you want to fade use something like:

Camera.main.SendMessage("fadeOut");

or

Camera.main.SendMessage("fadeIn");

Enjoy!

Introduction
Author: Adrian

Extended version written in Boo (put it into "Standard Assets/Scripts" to use it from within JavaScript files).

Main change is that rather than defining a fade speed you can set the duration of the fade in seconds.

Also provides methods to set the fade duration when the method is called and static methods to call the fade script on the main camera (by calling CameraFade.FadeInMain).

Introduction
Author: Kentyman

Hello everybody! I was looking for an easy way to fade the screen and found this page. The scripts here didn't do quite what I wanted, so I rewrote the C# version. This one will fade from any color to any color. Usage: use "SetScreenOverlayColor" to set the initial color, then use "StartFade" to set the target color and the fade duration (in seconds) and start the fade.

Introduction
Original Source: Kentyman Extended Source: dannyskim

I wanted to extend the functionality of Kentyman's implementation, so I decided to do a few things. - Make it into a Singleton so I don't have to write various amounts of code everywhere to do the same thing. The singleton also takes care of cleanup, which also involves not having to worry about a loose cannon OnGUI sucking up resources.

- I almost never use Color to Color fades. I typically use Alpha fades of one color, feel free to add the Color to Color fade if you wish.

- Add an OnComplete Action. I typically will use fades in scene transitions, so it's handy to pass in the instruction to       load a level instead of having to write a method every time you want to.

To use this Singleton, all you have to do is:

The above will fade out to a White screen, after a delay of two seconds. The fade will take two seconds, and then it will Load Level 1, and then automatically destroy itself, cleaning up the private static reference. It will also destroy itself after the OnFinish call, preventing OnGUI from running anymore.

Note: As of now, Lambda Expressions are not currently supported in the Flash beta of Unity3D, but regular Actions still are. To forego the possibility of Lambda Expressions breaking your .swf, simply pass in a void method instead of the Lambda Expression for OnComplete.

Since it is a singleton, the above line of code is all you have to do. No instantiating, no disabling the script, no finding the script via GetComponent<>, etc. Nice and easy.

Introduction
Author: ratmat2000

Extended version written in C# (put it into "Standard Assets/Scripts" to use it from within JavaScript files).

This version is identical to the Boo version but written in C#.

Source (CameraFade.cs)
The following bugs have been identified in the code segment above

LINE 133: FadeInOut should read CameraFade

LINE 136: Replace FadeInOut occurances with CameraFade

Also when I was trying to use it, if I didn't FadeIn on start the value for currentAlpha would end up NaN. I had to do some rearranging, but when I was done there were conditions that would cause currentAlpha to equal the targetAlpha when I issued a FadeIn command. I corrected this by placing the following code in the FadeIn method and an equivalent one in the FadeOut.

I would replace this code with mine, but I've already changed my so much I am hesitant to do so, I'll leave that exercise to someone else.