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 ???
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");
}
Manual - Coroutines
Tutorial - Coroutines
Script Reference - Coroutines
Unity Answers - Coroutines