Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mike9730 · Jan 27, 2013 at 04:21 AM · parsing error

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();
         
         }
     
                     }    
     
         }
     }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mike9730 · Jan 27, 2013 at 05:39 AM 0
Share

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.

avatar image AlucardJay · Jan 27, 2013 at 05:44 AM 0
Share

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).

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Jan 27, 2013 at 05:39 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges