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 yousif · May 07, 2011 at 06:34 PM · namespacesyntax-errorcs8025cs1525

Unable To Find Solution For Errors

Hello guys,

I have got this error: "error CS0116: A namespace can only contain types and namespace declarations"

For this piece of code, i think:

// Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.Tab)) { TargetEnemy();

}

}

This is my script:

[CODE]using UnityEngine; using System.Collections; using System.Collections.Generic;

public class Targetting : MonoBehaviour { public List Targets; public Transform SelectedTarget;

private Transform MyTransform;

// Use this for initialization void Start () { Targets = new List<Transform>();

 AddAllEnemies();
 SelectedTarget = null;
 MyTransform = transform;


}

public void AddAllEnemies() { GameObject[] go = GameObject.FindGameObjectsWithTag("Enemy");

 foreach(GameObject enemy in go)
 AddTarget(enemy.transform);

}

public void AddTarget(Transform Enemy) { Targets.Add(Enemy); }

private void SortTargetsByDistance() { Target.Sort(delegate(Transform t1, Transform t2) { return Vector3 .Distance (t1.position, MyTransform.position).CompareTo(Vector3.Distance(t2.position, MyTransform.position)); });

private void TargetEnemy() { if(SelectedTarget == null) { SortTargetsByDistance(); SelectedTarget = Targets[0];

 }


}

// Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.Tab)) { TargetEnemy();

}

}

As well as that error i have this one too: "error CS1525: Unexpected symbol `private' "

For i think this piece of code:

private void TargetEnemy() { if(SelectedTarget == null) { SortTargetsByDistance(); SelectedTarget = Targets[0];

 }


}

Thanks :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GesterX · May 07, 2011 at 06:58 PM

You're missing a closing curely bracket off your method "SortTargetsByDistance". Adding one will solve the second error - let me know if the first error still occurs...

Comment
Add comment · Show 7 · 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 yousif · May 07, 2011 at 07:08 PM 0
Share

Hello, thanks i did what you said and guess what.....it worked thanks man your a genuis; but i got another error : Assets/Scripts/Targetting.cs(67,5): error CS8025: Parsing error

The same script :(

avatar image GesterX · May 07, 2011 at 07:15 PM 0
Share

which line is this reffering to? Double click the error in the error console to find it.

avatar image yousif · May 07, 2011 at 07:20 PM 0
Share

// Update is called once per frame void Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Tab)) { TargetEnemy(); }

}
** This is the line that the flashy writing thing was on when i double clicked it ^^^^^^^

So basically the bottom line.

avatar image yousif · May 07, 2011 at 07:21 PM 0
Share

if you know what i mean, it's the line underneath the last bracket.

avatar image GesterX · May 07, 2011 at 07:31 PM 0
Share

You need a final curly brace at the end of the script to close the class

Show more comments

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

No one has followed this question yet.

Related Questions

A namespace can only contain types and namespace declarations 4 Answers

If CODE problems.. 1 Answer

Errors CS1525 and CS8025.... 1 Answer

Receiving parsing error when declaring a MenuObject. 1 Answer

Errors in Unity2D 0 Answers


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