Feature "local functions" not available in C# 4?

Hiya, encountered this issue today, and have no idea how to fix it

After searching online, found a fix for this issue. If you put the IEnumerator as a private variable, and outside the update method - the problem gets resolved. Hopefully this helps others too

1 Like

Hi Timur,

Yes, the issue isn’t so much about specifying the access modifier of private, C# will default to this anyway. The cause of your error is because you are placing one method inside another. In this case your method PrintAndWait has been placed within the Update method. The version of C# that Unity is referencing doesn’t support this, hence the error.

I believe from Unity 2018+ the version of C# which is supported has been upgraded, as such, local functions are supported, however, I would suggest avoiding them until you find a good reason to use them and understand why you may want to use them. :slight_smile:

Well done for managing to resolve your issue yourself though, and the detective work that was involved in doing so.

Thanks! I got confused by “I’ll just put this underneath the Update method” at 4:10 during the lecture and when the compiler gave an error, I had to re-watch it multiple times to figure out where I went wrong, but it’s totally my bad and perhaps a bad understanding of English :slight_smile: thanks for your response though! You are always really helpful and responsive

1 Like

Hi Timur,

I got confused by “I’ll just put this underneath the Update method” at 4:10

Ahhh, I see yes, I can relate to that and I wouldn’t put that down to being you or your understanding of English. Now you have explained what happened I can fully appreciate how, taken literally, you would end up with that outcome.

Also, you are not the first person who has done that, I have seen it quite a few times. I had often assumed that perhaps the student had the closing brace of the method off the bottom of the screen perhaps and didn’t realise, so just typed into the available white-space, which, was in the other method.

It isn’t likely to get an update, but I will feed this back to the team because I think that it is a really relevant point. :slight_smile:

You are always really helpful and responsive

That’s very kind of you to say, thank you :slight_smile:

Ah, I see. So this is in regards to saying “put this below Update” - which could mean within update, below the other content, or it could mean as a new method below the update code block.

Thanks for pointing this out, I’ll keep this in mind as I’m describing my coding in the videos.

1 Like

Cool, me too. Thanks for raising this @Timur_Kadrmetov and @Rob

1 Like

Privacy & Terms