- Home /
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 :)
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...
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 :(
which line is this reffering to? Double click the error in the error console to find it.
// 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.
if you know what i mean, it's the line underneath the last bracket.
You need a final curly brace at the end of the script to close the class
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                