Fading a text gui style

Hi,

I’m showing a message on screen and I would like to fade that message out after 3 seconds.

I created a gui style.

var myStyle : GUIStyle;
static var showText : String = "Welcome";

function OnGUI () {
	GUI.depth = 0;
	GUI.Label (Rect (Screen.width / 2 - 235, Screen.height - 40, 500, 50), showText, myStyle);
}

This code displays the text “welcome” but how can I make it fade out within 5 seconds? Each time I google I get directed to the wiki page about fade.js but I am not sure if that’s what I need. I tried using the fade.js but I don’t understand how I can fade in/out my text with that.

The color of your text is stored in your GUIStyle myStyle, probably myStyle.normal.textColor.
You could try changing the colors alpha component over time, that would be myStyle.normal.textColor.a

Using your code above, you could do something like:

this.myStyle.normal.textColor.a = 255;

This will set the alpha (a) to 255, fully visible. If you want to change it over time, simply make the alpha value a variable and modify it in OnGUI().

var Label2:GUIStyle = new GUIStyle(GUI.skin.GetStyle(“label”));
Label2.fontSize = 22;
Label2.normal.textColor = Vector4(1,1,1, 0.3 ) ;