Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

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

Discussion in 'Editor & General Support' started by Brian-Washechek, Jun 30, 2018.

  1. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    That's the error that I'm getting on this Asteroids tutorial. Here, see for yourself: Error on 6-30-2018.png 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.
     
    Last edited: Jul 1, 2018
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,399
    You spelled OnTriggerEnter2D wrong.

    --Eric
     
  3. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    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.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,399
    OnTriggerEnter2D is very different from OnTriggerEnter2d. Also, you can't put functions inside other functions.

    --Eric
     
  5. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    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!
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,399
    That's never been the case. It doesn't matter where functions are, aside from not putting functions inside other functions.

    --Eric
     
  7. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    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.
     
  8. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Well, I trust you over my bad memory.
     
    Last edited: Jul 2, 2018
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,399
    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
     
  10. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    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).
     
  11. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    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)