Feature 'local functions' is not available in C#.

That’s the error that I’m getting on this Asteroids tutorial. Here, see for yourself:

I did a quick web search for this and it’s the absence of positive results that I met that lead me to request assistance on this forum. Can anyone help me out here?

In the meantime I’m going to take a nap. Getting old isn’t fun.

You spelled OnTriggerEnter2D wrong.

–Eric

It doesn’t look wrong to me. My uncertainty lead me to copy and paste your version of the function name “OnTriggerEnter2D” into my project and my results didn’t change…

(?)

Am I missing something? I take it that I’m missing something.

OnTriggerEnter2D is very different from OnTriggerEnter2d. Also, you can’t put functions inside other functions.

–Eric

Wow, what a silly error I made! I thank you for your patience. It works now.

Way back when I coded part 1 of the series, you had to have function code ABOVE where you called it. Now I see that the compiler no longer requests this of you.

I once again thank you for your patience and assistance!

That’s never been the case. It doesn’t matter where functions are, aside from not putting functions inside other functions.

–Eric

Are you sure you never had to write them above were they’re called? I used to program games before my accident and I think it was it was then. My car wreck happened about a decade and a half ago. My car in wreck happened on 9-11-2004. My game library was written in Visual Basic in 2003/2004. I know my memory around that time has basically been deleted due to the wreck (I’ve been told that at the time I was attending The University of Wyoming and I don’t remember that), but I’m almost positive you had to place functions above where they’re called in the script.

My car wreck was completely my fault, by the way.

Well, I trust you over my bad memory.

It’s possible there’s some environment where that’s imposed, but I haven’t heard of it. It would be a very strange compiler limitation. I haven’t used Visual Basic, but I looked up functions in it, and the code examples have the function below.

–Eric

You forgot an ending curly brace } That’s why you were getting that error in the first instance - It thought you were declaring your function in the above function.

You can declare functions in any order in C#. You might be getting confused with C/C++, where you have to have the function above where you are calling it from (or use a function declaration).

Just FYI: I think you’re thinking of C / C++, that’s a compiler limitation there. It’s the reason why you have to have header files.

C# on the other hand was made to explicitly not require/have header files (or rather, made to not have the problems that require header files in the first place, like linear top-down parsing)