Question by
CrazyLule · Aug 26, 2016 at 06:31 PM ·
coroutinecoroutines
How do corutines work ???
Guys can somebody explain how corutines work
using UnityEngine; using System.Collections;
public class log : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine (testwait());
}
// Update is called once per frame
void Update () {
testwait ();
}
IEnumerator testwait()
{
Debug.Log("test");
yield return new WaitForSeconds (2f);
}
}
This dosent put in console test after 2 seconds ???
Comment
Answer by Jessespike · Aug 26, 2016 at 06:42 PM
This dosent put in console test after 2 seconds ???
No, because the 2 second wait is after the log. Put the wait before the log, like this:
// Use this for initialization
void Start () {
StartCoroutine (testwait());
}
// Update is called once per frame
void Update () {
}
IEnumerator testwait()
{
yield return new WaitForSeconds (2f);
Debug.Log("test");
}
Your answer
Follow this Question
Related Questions
Is there a way to check something every frame from within a coroutine? 1 Answer
Designing a dialogbox that displays message, returns a custom object and waits for user response 0 Answers
Best way (performance wise) to move multiple objects in certain time 0 Answers
Add points every five seconds 1 Answer
Coroutine or While loop that you can reset/add time too? 0 Answers