FadeInOut

From Unify Community Wiki
Revision as of 20:44, 14 May 2008 by PsychicParrot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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()

<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