I can’t figure out the cause of the problem. I’ve tried restarting Unity and rebooting my PC. I’ve tried passing string and method names. Switching 0 to null made no difference. Nothing ever changes. I’m always consistently getting either 1 Hello when yield comes before Debug.Log, and 2 Hellos when yield comes after. Any ideas??? I literally only put this online to ask this question here. I really think I need to have Coroutines work properly, I don’t know what the source of the problem is.
Github entire but simple project: GitHub - nastajus/CoroutinesLearning: Had difficulties implementing Coroutines per this site http://unitypatterns.com/introduction-to-coroutines/
Unity Patterns tutorial: http://unitypatterns.com/introduction-to-coroutines/
The most interesting result was when I append i to the output it prints 5 times instead. Very weird and confusing based off the tutorial.
void Start(){
StartCoroutine("SayHello5Times"); //doesn't work right
}
IEnumerator SayHello5Times(){
for (int i = 0; i < 5; i++){
//instructions: comment out other block
yield return 0;
Debug.Log("Hello"); //prints once
//Debug.Log("Hello " + i); //prints 5 times
}
}