Difference: yield WaitForSeconds() vs yield return new WaitForSeconds()

The question is simple. Regarding coroutines; what is the difference between using:

"yield WaitForSeconds(x)"

and using

"yield return new WaitForSeconds(x)".

The documentation uses the first one, but I see the latter being used a lot on answers, forums, and amongst co-students.

Totally agree this is a great question that, err, Eric5h5 should fully explain for evryone! :-) One note for any beginners reading - to avoid confusion: for simple timers in Unity just don't use coroutines in any way at all, just use Invoke() or InvokeRepeating(). See unityGEMS.com for endless articles on this.

1 Answer

1

You have to use yield return new WaitForSeconds(x) in C#, you don’t have to use it in Javascript. There is no difference.

I would like some verification of this. Documentation or approval from other user. At least before accepting an answer. :)

Ooook. The 30k Karma not enough for you huh? Well google finds this: http://docs.unity3d.com/Documentation/ScriptReference/index.Writing_Scripts_in_Csharp_26_Boo.html See section 4.

No offense meant. I'm just often a bit hellbend on being a 100% sure. Documentation appreciated.

None taken. I was already 100% sure ;) & hence had to search for the documentation myself!