- Home /
Programming Question with WaitForSeconds
Trying to get this to work but in my Debug.Log all I see is This is printed immediately, why am i not seeing the stuff in the Do() function?
Thanks.
IEnumerator Do() {
print("Do now");
yield return new WaitForSeconds(2);
print("Do 2 seconds later");
}
public void Awake() {
Do();
print("This is printed immediately");
}
Answer by boymeetsrobot · Oct 28, 2010 at 08:27 AM
This should be what you are looking for:-
void Awake() { StartCoroutine(Do()); }
IEnumerator Do() { Debug.Log("This will show instantly"); yield return new WaitForSeconds(2); Debug.Log("This will print after 2 seconds"); }
Answer by Mike 3 · Oct 28, 2010 at 08:19 AM
You need to use StartCoroutine(Do()); to call the function
Your answer
Follow this Question
Related Questions
Can I use StartCoroutine inside of the same coroutine with a new variable? 0 Answers
IEnumerator Function 2 Answers
WaitForSeconds does not work 0 Answers
Object Not Instantiating After Being Destroyed 0 Answers
IEnumerator in Update 2 Answers