Coroutines

u8 的头像

协同程序c#版,Coroutines in Unity3d (C# version)

Coroutines in C# work the same way that they do in Javascript (UnityScript), the only difference is that they require more typing (they have a slightly more complicated syntax). You should see the blog post on Javascript coroutines first.

Here, I present the differences:

Coroutines must have the IEnumerator return type:

1    IEnumerator MyCoroutine()
2    {
3        //This is a coroutine
4    }

u8 的头像

协同程序js版,Coroutines in Unity3d (Javascript version)

I’ve been working with Unity3d for some time now and I couldn’t really make good use of the coroutines because I was unable to truly understand them. After some time playing with them and making some experiments I realized their true power. I couldn’t believe what I was missing! So, a couple of fellow game devs asked me to explain the concept to them. I decided that a blog post was the perfect way to do it and, at the same time, share this with everyone.