This is a message pertaining to C# in Unity, but I'm assuming general C# knowledge will apply.
Take the following code:
class myClass
{
IEnumerator myEnumerator;
public IEnumerator theEnumerator()
{
int i = 0;
while (true)
{
Debug.Log(i++);
yield return null;
}
}
public void Update()
{
if (myEnumerator == null) { myEnumerator = theEnumerator(); }
myEnumerator.MoveNext();
}
}
If I instance that class, then call "Update" once per frame, I get the following output in the log:
0
1
2
3
4...
That works fine, however I want to implement some custom functionality in the IEnumerator itself. But if I create the following:
public class myIEnumerator : IEnumerator
{
public int myCustValue;
public void myCustFunction(){}
}
and then update the oringal class, replacing "IEnumerator" the "myIEnumerator", I get the following error:
The body of `myClass.theEnumerator()' cannot be an iterator block because `myIEnumerator ' is not an iterator interface type
What am I doing wrong here, and how can I make my own custom IEnumerator?
IEnumerable,IEnumerable<T>,IEnumerator, andIEnumerator<T>. Inheritance doesn't work for iterator blocks.