Hey all,
I'm trying to make a script that will allow me to fade the background. I've managed to find and edit one, namely this:
public var fadeOutTexture : Texture2D;
public var fadeSpeed : float = 0.3;
var drawDepth : int = -1000;
private var alpha = 1.0;
private var fadeDir : int = -1;
private var screenwidth = Screen.width;
private var screenheight = Screen.height;
function OnGUI(){
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color.a = alpha;
GUI.depth = drawDepth;
GUI.DrawTexture(Rect(0, 0, screenwidth, screenheight), fadeOutTexture);
}
function fadeIn(){
fadeDir = -1;
Debug.Log ("ScreenFade : Fading In");
}
function fadeOutIn(waitTime : float){
fadeOut();
Debug.Log ("ScreenFade : Fading Out and In");
yield WaitForSeconds (waitTime);
fadeIn();
}
function fadeOut(){
fadeDir = 1;
Debug.Log ("ScreenFade : FadingOut");
}
function Start(){
alpha=1;
fadeIn();
}
It works very well, but what I would like to is fade everything out, except for the GUI. I've tried managing this with GUI.Depth, but I read somewhere on the forum that the GUI is always on top, no matter what.
I'm drawing a background with DrawTexture (which I change dynamically throughout the game), so it's part of the GUI, and that means it either all fades, or nothing does.
Is there a way for me to assign a lower/higher depth to the individual DrawTexture, so I can isolate it (read: fade only that DrawTexture)? I guess what I need, is for this fade texture to get above the DrawTexture, but under the other GUI elements.
Thanks in advance,
Veliremus