- Home /
Need Text to Display After 5 Seconds
Hi,
I am at a very beginner level of scripting. I simply want to make some text that I have written in Canvas>Text, pop up on the screen after 5 seconds. I then want the text to stay on the screen after 5 seconds. (It will pop on the screen at 5s, and leave at 10s.
Please remember once again that I have minimal experience with scripting, so if you rewrite my code, could you please write it from beginning to end. Thank you so much for any help!
p.s I'm using Unity 4.6
#pragma strict
private var ShowlLabel : boolean = true;
function Start() {
yield WaitForSeconds (5);
ShowlLabel = true;
}
function OnGUI(){
if (ShowlLabel)
GUI.Label(new Rect(16, -103, 115, 19), "This headache is killing me, and I'm so tired that I can barely keep my eyes open!");
}
Are you using a Canvas with Text? Using GUI.Label is something else, its part of the old UI system not the new canvas system. Your code should work except your y value is $$anonymous$$us so its actually of the screen. $$anonymous$$ake it 103 not -103 and your width/height should probably be larger as 115,19 will truncate the string.
GUI.Label(new Rect(16, 103, 500, 19), "This headache is killing me, and I'm so tired that I can barely keep my eyes open!");
Yes, I'm using the canvas with text. So what would I put in place of GUI.Label?
Answer by karljj1 · Feb 22, 2015 at 11:40 PM
#pragma strict
public var myText : GameObject; // Assign the text to this in the inspector
function Start() {
yield WaitForSeconds (5);
myText.SetActive( true ); // Enable the text so it shows
yield WaitForSeconds (5);
myText.SetActive( false ); // Disable the text so it is hidden
}
Your answer
Follow this Question
Related Questions
Display GUI Text after delay ? 1 Answer
Problem Displaying Score on GUI text 0 Answers
TMPro text does not display correctly in Game View 3 Answers
Canvas Text gets garbled 0 Answers
How to display EULA from Doc in Unity? 0 Answers