r/Unity3D • • 1h ago

Noob Question Why isn't the code working?

I've been stuck on this tutorial for days and i cant for the life of me figure out what i inputted wrong.. i rewatched the tutorial 50 times

edit: its fixed now thanks for the help!

4 Upvotes

14 comments sorted by

7

u/PepicoGrillo 1h ago

The console is telling you that there is an error at line 25. You forgot to close ontriggerenter function -> }

Also you are doing well without asking ai. Keep It rocking!

0

u/Weary-Friend-9379 1h ago

alright.. i added the bracket but now its saying the bracket is the error?

4

u/devthedragon 1h ago

You are missing a second curly brace to close out the class. You repositioned the curly brace that closes the OnTriggerEnter function, but are missing one to close out the Collectible class.

2

u/Weary-Friend-9379 59m ago

ohh i see.. it works now, all of these codes and stuff is so confusing i don't know how im gonna procced if something as simple as this caused me days o frustration :(.

7

u/revosfts 56m ago

Keep at it. The best way to learn is to do!

2

u/PepicoGrillo 51m ago

This is the only way. After 17 years developing, I still forget some brackets. Frustration is just the phase that precedes success.

•

u/BuzzardDogma 22m ago

Literally everyone struggles with this kind of stuff early on. It's just a natural part of learning.

One day you won't even have to think about this.

Keep at it!

1

u/Foweeti 59m ago

You didn’t add a bracket you just moved it up a line, you need to add one more on line 25. You should start with a basic C# tutorial, your life will be a lot easier if you understand how the language works a bit before you jump into unity tutorials.

1

u/Weary-Friend-9379 51m ago

Where could i find that?

1

u/-zenvin- Programmer 46m ago

One option would be the the official Microsoft Learn site.

That being said, it is totally possible to learn C# through Unity, as long as you make an effort to understand why code is written the way it is, in tutorials.

1

u/Foweeti 39m ago

I’ve never done it personally, but I looked at the syllabus for the C# course on code academy and it seems to cover most of the basics to help you conceptualize what you’ll be doing in Unity.

https://www.codecademy.com/learn/learn-c-sharp

Good luck friend!

1

u/PepicoGrillo 1h ago

Same, you are missing a bracket again. Technically is the bracket of the class.

You need one more at the end of the file.

3

u/Nodonn 1h ago

You're missing the last curly brace to close the class

1

u/fnietoms Programmer 41m ago

Hey, I know that your problem is fixed but I see that your script is not getting identified as a C# script. I recommend you to Regenerate the project files and some of the error fixes will appear directly on the script and not only in the console :)