Romeno
1
I’m creating GameObject and adding MonoBehaviour to it.
go = new GameObject("sprite" + creepId);
mb = go.AddComponent<MonoBehaviour>();
Then I’m using mb to start coroutine
mb.StartCoroutine("coMove", new MoveData(Utils.ToVector2(go.transform.position), destPositions));
At run time I get Exception:
Coroutine 'coMove' couldn't be started!
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
JATD.Creep`1:Move(Vector2[]) (at Assets/JATD/Scripts/Creep.cs:68)
<Spawner>c__Iterator2:MoveNext() (at Assets/JATD/Scripts/MainGame.cs:103)
Any thoughts?
P.S. .NET 4.0 is set in the MonoDevelop project settings.
Use StartCoroutine(routine: IEnumerator) instead of StartCoroutine(methodName: string, value: object = null).
The co-routine must belong to the class you are starting it from, so in this case you created an empty mono behavior instance, so it has no coMove method.