Unity Coding Issue

Hi, I’m new to Unity and came across a coding issue while following the 2D course. It relates to a script that I’m trying to write. I’m having a hard time adding it as a component to one of my assets. Here is a screenshot of the error messages to give you a better idea. Can you help me?

I always appreciate the help.

Thanks

Hi,

Welcome to our community! :slight_smile:

You understood the error messages right. They do refer to a problem in your script. They are compiler errors that need to be fixed first. Otherwise, Unity cannot create a component. If you fix the errors, you will very likely be able to add the component.

Whenever you see something like ‘; expected’, there is very likely a semicolon missing, or maybe there is a misplaced character somewhere. Those are very typical problems, even for experienced programmers. For this reason, I would recommend to find and fix the problem yourself.

A little tip: Since there are multiple error messages stating that a character is missing, start with the first one by double clicking on it. Then check the line carefully. If you cannot spot any issue in that line, go to the line before, and so on. The compiler is not intelligent, so the messages could sometimes be misleading. The reason for that is: If a character is missing or misplaced, the compiler could misinterpret the code you actually wanted to type.

If you cannot spot any issue, remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Let me know if you found and fixed the problem! :slight_smile:


See also:

Hi, Nina, thanks for your help. This helps a lot. In fact, I figured out what the problem was. It turns out all I had to do was change the name of my C# Script so it matched in the “public class” section of the code. I’m glad it wasn’t anything complicated. I’m also glad there’s a Unity community out there to help us beginners out when we come across problems like this. Whenever I have a problem with coding in Unity, I know who to call. Thanks again for your help. I appreciate it. :grinning:

Oh, that was indeed a simple problem. :slight_smile:

Thanks for sharing the solution. Having to name one’s file after the class inside that file is required by Unity. In pure C#, it wouldn’t have mattered.

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

Privacy & Terms