For some reason the code below isn’t printing anything. I am not trying to start a coroutine, I only want to call it once and have it resume execution to where it left off the next time it is called.
void Start()
{
Debug.Log("Start");
Test4A();
Test4A();
}
IEnumerator Test4A()
{
UnityEngine.Debug.Log("Hello");
if (true)
{
UnityEngine.Debug.Log("Stop");
yield return null;
}
UnityEngine.Debug.Log("4");
}
“When you use the yield keyword in a statement, you indicate that the method, operator, or get accessor in which it appears is an iterator”
This means you have used a shorthand to define a class with a method which is used to iterate through an IEnumerable list, like you would in a foreach loop. While Test4A returns an IEnumerator, the method is used only when you attempt to get the next element. To do this use IEnumerator.MoveNext(), normally you would do something like
IEnumerator temp=Test4A();
while(temp!=null){
temp=temp.MoveNext();
}
but since you only want to call the method once you can just do
Test4A().MoveNext();