Strange problem with scripts

hi everyone

recently I’m having a really strange problem with scripts in unity and visual code
for some reason, all my new scripts come with these 4 errors

translation:
} expected
Top-level statements must precede such namespace and type declarations.
Namespace or type definition, or end of expected file
Local function ‘Update’ is declared, but never used

I tried to Reinstall Unity, visual studio code, and nothing
I tried to use visual studio community and end the same way

when I removed the variable, the problem disappears
and for some reason when I follow the solution for the problems, it disappears
idk what the hell is happening

this is my first post, sorry if i making something wrong


8676540--1169463--upload_2022-12-20_18-15-38.png

You’re trying to declare a public variable inside of the Start method. You can’t do that, which is why it is confused by the lack of a closing “}” before you declare that public variable.

1 Like

It’s quite simple. You’re trying to add a public variable into a method. Note, variables inside methods can not have accessors added to them.

So it’s not an error that comes with your script, it’s one that is created because of the variable. If you want a public variable, it needs to be declare inside the class and outside of the methods. Otherwise, don’t use the public on the variable.

@Joe-Censored Was faster. :smile:

2 Likes

Weird, it says my response was 10 minutes ago while yours was 9 minutes ago lol. Confused!

@Joe-Censored @Brathnann
ohh man sorry guys, i feel like an idiot right now lol
thanks for the help, I’m very noob in unity

1 Like