- Home /
How to make GUI Text appear after a certain amount of time
Hey everyone,
I have a GUI Text for my game, but I want it to appear after a certain amount of time. I know that I can use:
if(Time.time = 20)
{
EXECUTE CODE
}
But I don't know how to actually display the GUI Text in the EXECUTE CODE section.
Thanks
-Grady
Answer by Maarten · May 20, 2011 at 08:43 AM
You can use a GUI Label, so for example:
GUI.Label(new Rect(0,0,100,100), "MyTextHere");
The first parameter is a Rect, containing the position and the size of the Label, the second is your wanted text.
http://unity3d.com/support/documentation/ScriptReference/GUI.Label.html
[Edit] If you want to use styles, you use the following code:
GUIStyle myStyle = new GUIStyle();
GUI.Label(new Rect(0,0,100,100), "MyTextHere", myStyle);
In this style you can set the font size, text color, etc
do you know how to change the font and size... etc....? thanks!!! :)
it says it needs a semicolon at the end of the first line, but there is already one there, also what function?? OnGUI() or Update() or anything else?
thanks
There are no errors in the code supplied in the answers. You've probably made an error somewhere. You can place this code in the OnGUI.
Answer by Meltdown · May 20, 2011 at 11:03 AM
Since OnGUI() is called once per frame like the Update() method, you can do everything inside your OnGUI method.
function OnGUI()
{
if(Time.time >= 20) // If more than 20 seconds has elapsed
GUI.Label(new Rect(10,10,100,100), "20 seconds has elapsed");
}
bro i can understand that code But how can i disappear it when more than 5 sec ? ty
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
changing font + size of text 1 Answer
The gui disappears when i let go 2 Answers
Delay Gameplay While Displaying 3,2,1 go!!! 3 Answers
text display on touch 1 Answer