Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by abhishek7 · Feb 18, 2016 at 04:31 PM · errornamespacesimple

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!!

Comment
Add comment · Show 4
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 ByteVault · Feb 18, 2016 at 04:38 PM 0
Share

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.

avatar image troien ByteVault · Feb 18, 2016 at 04:43 PM 0
Share

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.

avatar image ByteVault troien · Feb 18, 2016 at 04:47 PM 1
Share

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

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · 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

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

43 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Having problem with 2D Roguelike tutorial Error: " error CS0101: The namespace `Completed' already contains a definition for `BoardManager'" 1 Answer

The Name 'GUID' does not exist in the current context 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