Hide GameObject after script has finished executing?
Hello, I've just started Unity so I'm new to this. I have GUI Text on the screen that is a component of GameObject. I'm using a script component that Auto types the text. I'd like it so that after the text has finished typing, the text (so I'm guessing GameObject) is hidden?
This is my script for Auto type
var letterPause = 0.2;
var sound : AudioClip;
private var word;
function Start () {
word = GetComponent.<GUIText>().text;
GetComponent.<GUIText>().text = "";
TypeText ();
}
function TypeText () {
for (var letter in word.ToCharArray()) {
GetComponent.<GUIText>().text += letter;
if (sound)
GetComponent.<AudioSource>().PlayOneShot (sound);
yield WaitForSeconds (letterPause);
}
}
Thanks
Answer by Jessespike · Nov 10, 2015 at 06:05 PM
To hide the GameObject:
gameObject.SetActive(false);
Alternatively, you can disable the GUIText:
GetComponent.<GUIText>().enabled = false;
Answer by centelleo · Nov 10, 2015 at 06:10 PM
@Jessespike Thanks for answering. How can I tell the game to wait until after the text has finished writing before hiding/disabling it? If I add it at the end of the code it simply stops immediately after being executed. Apologises this is probably a stupid question, again I'm still trying to get the hang of things.
Your answer
Follow this Question
Related Questions
HELP ! Highscore name input after each Death 0 Answers
Unity {[(2D)]} RotateAround while jumping 0 Answers
Why do I only have left/right mouse movement 1 Answer
2D Frogger Logs and Water issues 0 Answers