Greetings! I am trying to learn Unity and i use the 2D UFO Game tutorial but i get stuck at part 3 of 9. They want me to write some code (which seems very difficult by the way) and i write the code properly (without really knowing what the code does or means). But then, they want me to hit the Play button, which i do. Then i get a fault message. It says the game can not run as long as there are errors in my code…! Can anyone help me out?
I think i use Unity 5.6 if it matters.
(Sorry about the CAPITAL LETTERS )
“All compiler errors have to be fixed before you can enter playmode” it says.
And perhaps i should start with an easier tutorial?
I only used Game Maker once (can i mention other game engines in Unity forums?) so i have a little bit of experience with game engines but no experience with Unity.
Please don’t quadruple-post. If you need to change your message after it’s posted, use the Edit link found at the bottom of your original post.
If you don’t share your code and where the error messages are originating from, we can’t help you debug it. Paste the contents of your script file inside a code tag here (use the Insert → Code feature of the forums) and copy and paste the error message as it appears, as well. That’s important because the error message tells you exactly where the problem’s occurring.
Also, when something goes wrong, always double-check your assumptions. You most likely have a faulty assumption right here:
Most likely you didn’t enter the code quite right. It could be something as simple as a misplaced punctuation mark, or incorrect capital/lowercase.
The other possibility is that you typed the code as shown, but the tutorial is out of date — occasionally a Unity function is removed, and you need to use a different method.
But of course the relevant bit of feedback is not “All compiler errors have to be fixed before you can enter playmode” (which is true but unhelpful), but rather the actual error (or errors) that you have. Those are what you need to pay attention to and fix… and if you need help, those are what you need to copy & paste here.
Well Joe, it seems like you assume quite a bit yourself.
I don´t know exactly what went wrong. I douvle checked the code but i think something else went wrong. Maybe i did not save the code properly or maybe the code did not get attached to the “Player” sprite in the tutorial. It did not work for some reason.
And i never claimed the key to the problem was the error message. Instead, i figured i would share it just in case it had some importance.
Unfortunately i think i did not save the code properly. So i can´t show it to you. It was not a lenghty string of code anyway so i just figured i would try again later an rewrite the whole thing.
Hmmm, maybe the code did get saved after all? I found it in the list among the project files. I also found an error message while looking.
“Paste the contents of your script file inside a code tag here (use the Insert → Code feature of the forums) and copy and paste the error message as it appears, as well. That’s important because the error message tells you exactly where the problem’s occurring.”
I can´t, Schneider21. I think the whole thing did not get saved properly. I will just try again to use the tutorial.
But i need to know… How do i know if the script even got added/attached to my player sprite (the UFO sprite)?
I will attach a picture of the code so you can check it out. But i think the code did not get associated with the “Player” sprite. But there could also be some error in the code. I am not used to writing code. I just tried to write the same code as in the tutorial.
Hmm, seems like i can´t attach pictures?
But maybe the following helps?
“Assets/PlayerOneControllers.cs(18,3): error CS1525: Unexpected symbol `rb2d’”
PlayerOneControllers is what i named the script. And rb2d was what i should write according to the tutorial (it means RigidBody2D which is a physics i previously added to the UFO Sprite because the tutorial told me to)
Here you go… A picture of the screen in Unity. Perhaps the code is full of errors. You could be right i guess. But it seems also like the “Player” sprite did not get associated with the PlaterOneControllers script. Hmmm…
Maybe, but because I’ve been doing this (both using Unity, and helping Unity newbies) for years, my assumptions are probably correct. You do want help, right?
Correct; there are two possible reasons, which I described above. Until you actually provide the error message (not the one about errors needing to be fixed, but the actual error message, which would be in the Console just before that), it’s hard to guess which one is the case.
You didn’t share the correct error message; you shared the useless one. We’re trying to help you look at the actual error message, i.e., the one describing the problem.
The code did get saved, or you wouldn’t get a compiler error (Unity compiles the code when you save it; and the initial default script contains no errors).
So, the screen shot shows one problem — and I think if you read the error and try to understand what it’s saying, it’s pretty clear: “No MonoBehaviour scripts in this file, or their names do not match the file name.”
So look carefully: is there a MonoBehaviour subclass in this file? And if so, does its name match the file name? (Note that it must match exactly, except for the .cs file extension.)
Correct that mistake, and then see if you get more errors. If you do, and reading and thinking about the error message doesn’t tell you how to fix it, then (1) copy and paste your script, using the Insert Code procedure @Schneider21 described; don’t paste a photo of your screen; and (2) also copy and paste the actual error, which you will find in the Console with a little red stop sign next to it.
Ehm, i still don´t get why things get wrong. Maybe i should just try an easier tutorial with no scripting involved ( i mostly want to learn Unity and how it works, scripting and coding seems…scary! I don´t even know what a subclass is…). But above you can see the code i use (i copied it). (i did not use the procedure Schneider21 described, perhaps just copying and pasting is inadequate?)
You think the bold line is wrong? The name in the script has to match with the name in the Unity files right?
Hmmm, now it seems to work. The UFO drops down just like the tutorial says it should. So weird. Well thanks for trying to help me out. I don´t know why it seems to work now but i appreciate the effort.
Well, I’m glad you got unstuck! If you have more issues with this tutorial, please post to its official thread, and keep in mind all the “how to post a good question” tips that @Schneider21 and I have tried to share.
For the record the problem was the missing semicolon at the end of line 17. Unexpected symbol errors are almost always to do with what happened immediately before the symbol listed on the error.
Moral of the story: Trust @JoeStrout 's assumptions and don’t confuse him with other stuff. Had you posted the code and error as asked instead of getting all offended he likely would have spotted the error on about half a second.