Unity cannot be an iterator block because 'void' is not an iterator interface type

Viewed 96

I have the code:

void sayText()
    {
        for(int i=0; i<startDio.Length;i++){
            setText(startDio[i],0);
            while(!Input.GetKeyDown(KeyCode.Space))
            {
                yield return null;
            }
        }
    }

and Unity gives me the error:

Assets\scripts\NPCtext.cs(16,10): error CS1624: The body of 'NPCtext.Start()' cannot be an iterator block because 'void' is not an iterator interface type

I suspect the "for loop" is causing this issue, but how do I fix it?

sideNote: The setText void is just to change the TextMeshProUGUI.

1 Answers

You cannot use yield in the method with return type of void. You need IEnumerator return type for that.

Related