- Home /
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.
Check the examples here :
Answer by worldspawn · Sep 30, 2012 at 01:51 PM
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
Could you give me a small example? I am not really sure what you mean.
Answer by irdc · Feb 27, 2013 at 01:50 AM
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().
that's almost right but it's wrong, 255 is .js, unity3d is 0-1 alpha
Answer by drudiverse · Jun 19, 2014 at 07:14 PM
var Label2:GUIStyle = new GUIStyle(GUI.skin.GetStyle("label"));
Label2.fontSize = 22;
Label2.normal.textColor = Vector4(1,1,1, 0.3 ) ;
Your answer
Follow this Question
Related Questions
Javascript/Unityscript or c# String obfuscator ... 2 Answers
Problem with text from a .txt file. 1 Answer
How to make GUI Text appear after a certain amount of time 2 Answers
Gui Button Solid 2 Answers
Controlling text speed 1 Answer