Hello I am getting this errors

After adding AudioSource to my collision I encountered this two errors:
-Assets\Scripts\CollisionHandler.cs(65,5): error CS8803: Top-level statements must precede namespace and type declarations.
-Assets\Scripts\CollisionHandler.cs(83,1): error CS1022: Type or namespace definition, or end-of-file expected

I am following the tutorial and haven’t seen any discrepancies between my code and Rick’s

please help!


1 Like

Hi there!

The error is telling you that there’s something wrong with the encapsulation of your code, you might want to double-check your code to that of the instructor.

Hint

Look at the dotted lines that connect your brackets.

Solution

Your brackets are off. There’s an extra bracket at line 55, remove it. This is why code formatting is so important, part of your code has an extra indentation starting at line 41, you might want to put it at the same indentation level as your OnCollisionEnter method to avoid confusion.

Hope this helps!

1 Like

Thanks for the help. Now I am getting no audio when crashing and landing on the finish platform. Not an error but I am getting these warnings!

Hope you can help!

The audio clips are probably empty, set them in the inspector, that should solve the no audio issue and remove the warning.

Hope this helps!

hey Yee,

If you mean to add it to the player on the inspector. It is already been added, been stuck here for while now cant find what may trigger this warning!

What do you mean by adding it to the player? Adding what exactly? The script or the audio clip to the script attached to the player?

I was able to fix it. Found out that I had multiple scripts attached to my object.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms