Namespace error....what???
After I updated my Unity version from 5.1.1p2 to 5.2.3, I've been having so many frustrating problems, many of which I've already resolved, but this is one of the remaining ones. For some reason I keep getting the error:
Assets/Scripts/Mecanim_Control_melee.cs(5,14): error CS0101: The namespace global::' already contains a definition for
Mecanim_Control_melee'
And I have no idea why. Here's the code in that script:
public class Mecanim_Control_melee : MonoBehaviour {
public Animator animator;
public bool leftMouseClick=false;
public bool rightMouseClick=false;
public bool canControl=true;
private float shift_axis_late;
public float leftMouseClicks;
private float animLayer2;
public float inputX;
public float inputY;
public float inputJump;
void Start () {
animator = GetComponent<Animator>();
}
void OnAnimatorIK(){
animator.SetLayerWeight(1, 1f);
animator.SetLayerWeight(2, animLayer2);
if(canControl){
Vector3 camDir = transform.position - Camera.main.transform.position;
Vector3 lookPos = transform.position + camDir;
lookPos.y = transform.position.y -(Camera.main.transform.position.y - transform.position.y) + 10f;
//animator.SetLookAtWeight(0.2f, 0.2f, 0.8f, 0.99f);
//animator.SetLookAtPosition(lookPos);
}
}
void Update () {
if(leftMouseClick){
StartCoroutine("TimerClickTime");
}
if(animator){
shift_axis_late = Mathf.Clamp((shift_axis_late - 0.005f), 0.0f, 1.1f);
animLayer2 = Mathf.Clamp((animLayer2 - 0.01f), 0.0f, 1.0f);
animator.SetBool("LeftMouseClick", leftMouseClick);
animator.SetFloat("LeftShift_axis", shift_axis_late);
animator.SetFloat("Axis_Horizontal", inputX);
animator.SetFloat("Axis_Vertical", inputY);
animator.SetFloat("Jump_axis", inputJump);
animator.SetBool("RightMouse", rightMouseClick);
}
if(canControl){
inputX = Input.GetAxis("Horizontal");
inputY = Input.GetAxis("Vertical");
inputJump = Input.GetAxis("Jump");
leftMouseClick = Input.GetMouseButtonDown(0);
if(Input.GetKeyDown(KeyCode.LeftShift)){
shift_axis_late += 0.25f;
}
if(Input.GetAxis("Fire2")>0){
rightMouseClick=true;
animLayer2=0.5f;
}
else{
rightMouseClick=false;
}
//sync animator Y_axis rotations with Main Camera
if(inputX+inputY!=0){
Vector3 camDir = transform.position - Camera.main.transform.position;
Vector3 lookPos = transform.position + camDir;
lookPos.y = transform.position.y;
transform.LookAt(lookPos);
}
}
}
void FightCombo(){ //every left mouse click +1 to animation number counter
leftMouseClicks += 1f;
animator.SetFloat("LeftMouseClicks", leftMouseClicks);
if(leftMouseClicks>2f){
leftMouseClicks = 0f;
}
}
IEnumerator TimerClickTime(){ //timer, few seconds after click mouse bool leftMouseClick = true
yield return new WaitForSeconds(0.1f);
leftMouseClick=false;
yield return null;
}
IEnumerator InAction(){ //recieve message from fight animation in mecanim controller
yield return null;
}
IEnumerator AnimationEnd(){//recieve message from fight animation in mecanim controller
yield return null;
}
}//The END
Any help would be seriously appreciated!!
You have another script who is using thesame namespace: $$anonymous$$ecanim_Control_melee
.
Im assu$$anonymous$$g you have imported atleast one package which use mecanim and some of them may include thesame or modified script and therefor gives this error.
Try rena$$anonymous$$g this scripts namespace with a "2" in the end.
$$anonymous$$ecanim_Control_melee2
If this works I would rename the script to thesame name as the namespace to make it easier to see which is which.
Although your answer is correct in how to resolve it. '$$anonymous$$ecanim_Control_melee' would be the class name. not the namespace. therefore you need to rename the class name, not the namespace ;)
Namespace is not defined in the script, resulting in the default global namespace which is fine. But this global namespace contains 2 classes with the same name, resulting in that error.
Thanks for explaining this to me. Been wondering but never actually taking the time to check for an accurate answer :)
EDIT: I think i've just always assumed that the class name would become the namespace after "it takes it space in the name" lol
I knew my answer would not be as good as the usual guys around here so I added a comment ins$$anonymous$$d of an "Answer" post :)
Answer by Sykoh · Feb 18, 2016 at 04:43 PM
This means the class called "Mecanim_Control_melee" has already been defined in the global namespace as the files do not have a predefined namespace.
In the asset file system the files themselves cannot have the same name but the classes within them can (if the classes are in different files).
By bet is that you copy and pasted the file and renamed it so you could mess with it but forgot to change the class name in the file to match and now there are 2 files with different names but each contain a class with the same name?
I could have explained this better. Sorry.
But check similar files for classes that are named the same.
Your answer
Follow this Question
Related Questions
Custom package's namespace isn't recognized by Unity or VS 0 Answers
A namespace cannot directly contain mambers such as fields or methods... 2 Answers
"namespace or end of file expected" Not sure what to do. 2D Rouge-Like Tutorial 1 Answer
The Name 'GUID' does not exist in the current context 1 Answer