Skip to content

Instantly share code, notes, and snippets.

@miguel12345
Last active August 29, 2015 14:24
Show Gist options
  • Save miguel12345/27b7db69cd17a3128ae8 to your computer and use it in GitHub Desktop.
Save miguel12345/27b7db69cd17a3128ae8 to your computer and use it in GitHub Desktop.
using System.Collections;
//Shouldn't we see the Debug.Log ("End printing") ?
public class EnumTest : MonoBehaviour {
static int a = 0;
IEnumerator printRoutine = null;
void Start() {
StartCoroutine (main ());
StartCoroutine (endPrinterAfter (4.0f));
}
IEnumerator endPrinterAfter(float seconds) {
yield return new WaitForSeconds (seconds);
StopCoroutine (printRoutine);
}
IEnumerator main() {
Debug.Log ("Begin printing");
printRoutine = printer ();
yield return StartCoroutine (printRoutine);
Debug.Log ("End printing");
}
IEnumerator printer() {
while (true) {
Debug.Log("Printing "+(a++));
yield return new WaitForSeconds(0.5f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment