- Home /
Question by
SEDBC3 · Jun 18, 2013 at 05:25 PM ·
gameobjectinstantiatewaitforsecondssetactive
How do I make a game object appear a few seconds into the game?
Hey guys, I know this question has been asked before but nothing I've been trying seems to be working. The script I'm currently using is this: #pragma strict
function Start () {
gameObject.SetActive(false);
WaitForSeconds(10);
gameObject.SetActive(true);
}
And the gameObject.SetActive(false) is straight from a Unity tutorial. I attached the script to the object and I can't figure out what I'm doing wrong. Any help would be much appreciated. Thanks!
Comment
Best Answer
Answer by create3dgames · Jun 18, 2013 at 05:53 PM
Your WaitForSeconds
does not have a yield
in front of it.
Also, make sure you do not have the script attached to the object which you are deactivating.
Your script should be like this:
#pragma strict
public var object : GameObject;
function Start ()
{
object.SetActive(false);
yield WaitForSeconds(10);
object.SetActive(true);
}
You should also do this in a coroutine rather than in Start.