Flash export: "yield return i;" not supported

I’ve just created a new empty project and created this script.

using System.Collections.Generic;

public class Whatever
{
  private IEnumerable<int> Count3()
  {
    for (int i = 0; i < 3; i++)
      yield return i;
  }
}

This project cannot be exported to flash. I get an error.

Usage of a type or method not supported by Unity Flash.

  • Details: Invokes an unsupported method System.Int32
    System.Threading.Interlocked::CompareExchange(System.Int32&,System.Int32,System.Int32)
    on type System.Threading.Interlocked

  • Source: E:/Unity/EpicFail/Assets/Whatever.cs(�6) at line : 6

Does anyone know why this happens? I use Unity 4.

“yield return X” isn’t really a legal command. Unity Editor probably guessed what it meant, but Flash refuses. Are you trying to pause for 0+1+2 frames? There’s probably a way to rewrite this to be completely legal and look nicer.

Take a look at Yield return to wait for some frame problem - Questions & Answers - Unity Discussions