- Home /
yield waitforseconds doesnt work on function start
Hi guys, I have a script where you press a button then an object comes true, and that object has a timer script on it that says:
var Example1 : GameObject;
var Example2 : GameObject;
function Start () {
yield WaitForSeconds (60);
Example1.SetActive(true);
Example2.SetActive(false);
}
The first time it works but when the timer stops the button comes back so the player can click it again but the timer does not work the second time. Any help appreciated! (This game is being released 31/10/15 so please help quick!)
Answer by JA_555 · Oct 27, 2015 at 05:44 PM
var Example1 : GameObject;
var Example2 : GameObject;
function Start() {
InvokeRepeating("repeat", 60f, 60f);
}
function repeat(){
Example1.SetActive(true);
Example2.SetActive(false);
}
I think that's it
Answer by Munchy2007 · Oct 27, 2015 at 10:18 AM
Start is only called once during the lifetime of an object. Unless you destroy and re-instantiate the object that this script is attached to, your coroutine will only ever run once.
If you don't want to destroy and re-instantiate, try calling your button coroutine from OnEnable() instead. (You will need to make a new coroutine rather than using Start()).
Your answer
Follow this Question
Related Questions
yield WaitForSeconds preventing further actions. 1 Answer
Can't Stop couroutines 1 Answer
Is there any way to stop WaitForSeconds() ? 1 Answer
Setting Scroll View Width GUILayout 1 Answer