yield break; gives me UCE0001: ';' expected. Insert a semicolon at the end.

i’m using yield break; in a co routine but the editor it gives me a UCE0001: ‘;’ expected. Insert a semicolon at the end. there is a semi colon at the end so i’m not sure what to do? i’m using unity script and any help would be very much appreciated.

function Break()
{
if(cancel){
yield break ;
}
else{
yield 2;
// do stuff//
}
}

I found a post that explains what i was doing wrong, All i needed to do was use return… Doh

from Jonathan Czeck,

JavaScript → C#

yield; → yield return 0;
return; → yield break;
yield WaitForSeconds(1.5); → yield return new WaitForSeconds(1.5f);

1 Like

“yield return 0” in C# should be “yield return null” ideally. That’s the same as “yield” in Unityscript.

–Eric