The question is answered, right answer was accepted
Unity Parsing error
Hello, i was wondering if you guys could point out what is wrong with this C# code.
using UnityEngine; using System.Collections;
public class PlayerScript : MonoBehaviour {
// Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.name=="machineGun") { Debug.Log("Object picked up "+ hit.gameObject.name); Destroy(hit.gameObject); } }
Could you format your code? It's difficult to see what might be causing you a problem without this. In particular, it would be good to see where you have line breaks.
Answer by fafase · Nov 03, 2012 at 06:07 PM
You are simply missing a } I think.
using UnityEngine; using System.Collections;
public class PlayerScript : MonoBehaviour { //1
void Start () { } //Closing
void Update () { } //Closing
void OnControllerColliderHit(ControllerColliderHit hit) { //2
if (hit.gameObject.name=="machineGun") { //3
Debug.Log("Object picked up "+ hit.gameObject.name);
Destroy(hit.gameObject);
} //2
}//1
Your code looks like this and you are not closing the class.
Yep I confirmed it, there was a missing closing curly!
Thankyou guys, sorry for perhaps the noob question. Just began my rather...awkward? journey into program$$anonymous$$g/scripting.
Don't worry, we all started one day and your error is nothing unusual. Some big projects even use program to check the missing brackets.
Answer by inslayn · Jan 10, 2013 at 10:10 AM
I also got this issue after performing a merge of conflicted files. In that case, Unity was reporting a parsing error, even though all the curly braces were there.
It turned out that the solution for that situation was to copy the contents of the file, then delete it. I then created a new file with the same name and pasted the contents I had copied into it.
Unity was then able to compile it correctly.
Yep. I often have to do this(every 3 scripts) because unity does not recognize the files. Sure is annoying.
You are likely, inadvertantly, adding in characters that look like whitespace but are not whitespace. Dont code in Rich Text Format for example.
Follow this Question
Related Questions
Parsing error, 1 Answer
Invalid PBX project - iOS Build Help! 2 Answers
error CS8025: Parsing error 1 Answer
Parsing error 1 Answer