Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved } closes class, but should only close the Start() function

Discussion in 'Getting Started' started by Kaesesnack, Apr 22, 2024.

  1. Kaesesnack

    Kaesesnack

    Joined:
    Apr 10, 2024
    Posts:
    44
    Hello dear forum,

    I currently have an error (probably incredibly easy to solve). It's embarrassing.

    Unity is throwing me wild error messages in places where there weren't any before.
    In MVS it tells me that a } essentially ends the whole file, even though it is intended for the Start() function. Since there is no other } there, I don't know why he sees it that way...

    At first I thought that I had forgotten a bracket somewhere, but for all the others they are recognized correctly.
    The last K} after Update() probably doesn't have an associated {...

    I'm adding the file...
    Please help me, I'm going crazy...

    Of course, this image only shows part of the file
    11.JPG
     

    Attached Files:

  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,709
    You're using keywords that aren't permitted in the method like
    public
    and
    readonly
    and it's confusing the compiler. Your IDE should have highlighted this with a red squiggly line. I checked and it's being highlighted by Visual Studio.
     
    Last edited: Apr 22, 2024
    Kaesesnack likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,683
    Ryiah likes this.
  4. Kaesesnack

    Kaesesnack

    Joined:
    Apr 10, 2024
    Posts:
    44
    Thank you @Ryiah :)
    Now I see that the 'public' causes the error.
    Since Visual Studio shows 'no problems found' and the bracket is not marked in red, I assumed it was a missing bracket or something. No wonder I didn't find anything like that.

    The public text slipped into the Start() function for me, although
    it should actually be above it.
    Well, I moved both lines and now it works.

    Thanks again :)

    @MevMay
    I added the image to show that Visual Studio didn't mark anything incorrectly in the section in question.
    I may have expressed this incorrectly, sorry.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,683
    Presumably you do have the Visual Studio package installed and it's set to be used in the Editor preferences?

    FYI, I was also referring to the attached source file too.