- Home /
How to enable object after delay ?
Hey fellas, I need help, to enable text after some time (4 secs), it's a tutorial text . Thanks.
Yeah, I get that, the thing is, I don't really know how to activate the text. It's simple 3D text, that I want to appear after my first text disappears after delay of 4 secs. And I want the second to come up.
So you just have to destroy the first text and instantiate the second. Take a look at how to use these functions at the docs:
http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
Sorry for not giving a long explanation, I hope this helps anyways.
Answer by bentog · Oct 30, 2013 at 04:56 PM
http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html
You can use Yield WaitForSeconds(4);
to wait 4 seconds. Then you can enable the text however you'd like (not sure what your text is like).
Answer by Tomer-Barkan · Oct 30, 2013 at 07:13 PM
Create an array of texts, and a co-routine that switches between texts. Any number of texts will work, not just 2.
private string[] texts = {
"First text",
"Second text",
"Third text",
};
public void Start() {
StartCoroutine(TextSwitcher());
}
public IEnumerator TextSwitcher() {
for (int i = 0; i < texts.Length; i++) {
GetComponent<TextMesh>().text = texts[i]; // switch to next text
yield return new WaitForSeconds(4); // wait 4 seconds before switching again
}
// after all texts displayed, disable text altogether.
GetComponent<TextMesh>().text = ""; // empty text
}
Your answer
Follow this Question
Related Questions
Delay gameplay and show text: 2 Answers
How to draw GUI Text from code 1 Answer
destroy object after a delay? 6 Answers
Make object visible in dark 2 Answers
Creating a callout text for 3d object,Creating a callout UI text on object file in unity 1 Answer