Yield return new WaitForSeconds(5f); don't work

Hi all, i have a problem with a yield waitforseconds, its give this error: The body of ‘TriggerAndLoadLevel1.TriggerHole(int)’ cannot be an iterator block because “void is not an iterator interface type”.

This is my script:

public void TriggerHole(int index) {
        holeTrigger[index] = true; //Set the hole trigger to true
       
        //Check if all holes have been triggered
        if (AllTriggered) {    
            UnlockLevels ();   //unlock next level funxtion
            yield return new WaitForSeconds(2);
            Application.LoadLevel ("fLevel1");
        }
    }

What is the problem?

use “public IEnumerator” instead :

public IEnumerator TriggerHole(int index){
2 Likes

thanks for your reaction, the error is gone, but the function of my code does not work any more, there is a timer in the scene that loads a scene when its reach 0, but when you finished the level before the time is over it will load fLevel1, but now it wait when the timer reach zero and than starts it the level when you reach zero but it must be fLevel1, what is the problem?