- Home /
Parsing Error
So I'm receiving a parsing error. The line that I'm getting at error on is a } and it doesn't close anything, so I figured that I could just delete it and it was my mistake, but when I did, it just messed up the script, here is the whole script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Target : MonoBehaviour {
public List<Transform> Targets;
public Transform SelectedTarget;
private Transform MyTransform;
// Use this for initialization
void Start () {
SelectedTarget = null;
Targets = new List<Transform>();
AddAllEnemys();
MyTransform = transform;
}
public void AddAllEnemys() {
GameObject[] Go = GameObject.FindGameObjectsWithTag("Enemy");
foreach(GameObject Enemy in Go)
AddTarget(Enemy.transform);
}
public void AddTarget(Transform Enemy){
Targets.Add(Enemy);
}
private void SortTargetsByDistance(){
Targets.Sort(delegate(Transform t1, Transform t2) {
return(Vector.Distance(t1.position, MyTransform.position).Compareto(Vector3.Distance(t2.position, MyTransform.position)));
});
}
private void TargetEnemy()
{
if(SlectedTarget == null)
{
SortTargestByDistance();
SelectedTarget = Targets[0];
}
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(1)){
TargetEnemy();
}
}
}
}
Answer by Julien-Lynge · Jan 27, 2013 at 05:07 AM
As a general rule, every open bracket ('{') has to have a corresponding closing '}'.
You'll have one opening '{' at the start of your class declaration at the top, and one at the end of your script.
Beyond that, you'll have one pair for each method, one pair after the if statement, and one pair for the Sort.
Your script doesn't match that pattern, so you'll want to clean it up.
If you're unsure how to do so, I highly recommend finding an introductory C# (or general programming) tutorial online.
I understand that, but my issue is that from what I see on my code, every bracket is closed even monobehavior, and if I am correct the last closing bracket should be for monobehavior, but the last one on my code is not closing anything, and when I delete it it throws off the whole code.
In monodevelop, if you highlight the parenthesis or place the curser where you type straight after it, the opposite parenthesis should also highlight, so you can see which opening belongs to which closing. You need to check this (and should already have if you understand). From what I see you have an extra closing parenthesis at line 73 (69 closes the if statement, 71 closes the update, 74 closes the class).
Julien has given you the correct answer (upvoted).
Answer by Mike9730 · Jan 27, 2013 at 05:39 AM
I understand that I have to close with "}" but the line that Iam getting an error connects to nothing, if I'm correct the last bracket should close MonoBehaviour.
Hi There.
Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.
Here at Unity Answers, Answer means Solution, not Response.
You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]
Under the answer where it says edit | delete | more , click on more , then convert to comment
Also you don't have to wait for a moderator to approve a comment.
Your answer
Follow this Question
Related Questions
Unexpected Symbol 'end-of-file' C# Error CS8025 1 Answer
error CS8025: Parsing error 2 Answers
Problem parsing package with API level 29 2 Answers
Parsing Error with creating new shader script 0 Answers
Unexpected symbol 'private' ... 1 Answer