title: Combining Coroutines and Reflection in Unity
body: <p>I'm trying to figure out how can I combine <strong>StartCoroutine()</strong> with <strong>methodInfo.Invoke()</strong> in Unity.</p>
  
  <p>First, the very basic, explicit calls code which I'd like to avoid:</p>
  
  <pre><code>if (ACTION_MOVE == action) {
      StartCoroutine(robotBehaviour.move());
  }
  else if (ACTION_ROTATE == action) {
      StartCoroutine(robotBehaviour.rotate());
  }
  ...
  </code></pre>
  
  <p>The called methods look like this:</p>
  
  <pre><code>public override IEnumerator move()
  {
      for (int i = 0; i &lt; ITERS; i++) {
          // Do something
          yield return new WaitForSeconds(N);
      }
  }
  </code></pre>
  
  <p>So with a little bit of reflection, I managed to make the call dynamically:</p>
  
  <pre><code>RobotBehaviour robotBehaviour = getRobotBehaviour()
  Type type = robotBehaviour.GetType();
  MethodInfo methodInfo = type.GetMethod((string)sentences[lineNo]);
  result = methodInfo.Invoke(robotBehaviour, null);
  </code></pre>
  
  <p>However, now I can't manage to invoke <strong>robotBehaviour</strong> with <strong>StartCoroutine()</strong>. </p>
  
  <p>Any ideas?</p>