FadeInOut

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: 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 te...)
 
Line 2: Line 2:
  
 
Simply apply it to your camera (or an empty GameObject), set the texture to use, set the fadeSpeed and call fadeIn() or fadeOut()
 
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!
  
 
<javascript>
 
<javascript>

Revision as of 15:45, 17 May 2008

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!

<javascript>

// FadeInOut // //-------------------------------------------------------------------- // Public parameters //--------------------------------------------------------------------

public var fadeOutTexture : Texture2D; public var fadeSpeed = 0.3;

var drawDepth = -1000;

//-------------------------------------------------------------------- // Private variables //--------------------------------------------------------------------

private var alpha = 1.0;

private var fadeDir = -1;

//-------------------------------------------------------------------- // Runtime functions //--------------------------------------------------------------------

//--------------------------------------------------------------------

function OnGUI(){

alpha += fadeDir * fadeSpeed * Time.deltaTime; alpha = Mathf.Clamp01(alpha);

GUI.color.a = alpha;

GUI.depth = drawDepth;

GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture); }

//--------------------------------------------------------------------

function fadeIn(){ fadeDir = -1; }

//--------------------------------------------------------------------

function fadeOut(){ fadeDir = 1; }

function Start(){ alpha=1; fadeIn(); } </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox