Im trying to learn how to use yields and stumbled upon this example. Why wont this works? myMethodYield never prints and I just cant understand why. Isnt yield supposed to do some code, interrupt and come back again later? In this case, if I understood it right, it should come back after 1 frame.
Thank you!
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class FuncAsParamTest : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Debug.Log( "Update world" );
MyClass mc = new MyClass( );
mc.funcTest( mc.myMethodYield); //never prints
mc.funcTest( mc.myMethod2);
mc.myMethodYield(); //never prints
}
class MyClass
{
public void funcTest( Func<object> methodToRun )
{
Debug.Log( "Callig MethodToRun" );
methodToRun( );
}
public IEnumerator<object> myMethodYield( )
{
Debug.Log( "myMethod - hello world" );
yield return null;
Debug.Log( "myMethod - after yield" );
yield return null;
}
public object myMethod2( )
{
Debug.Log( "myMethod2 - hello world" );
return 0;
}
}
}