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
2
Question by zakaria92 · May 25, 2017 at 03:27 PM · error messageerror-building-playererror reporting

error CS0101: The namespace `global::' already contains a definition for `GameManager'

hello Im very new to the whole scripting and unity engine . When importing project , I have this error

error CS0101: The namespace global::' already contains a definition for GameManager' alt text

When I click the error appears to me :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
     [Header("Setup Level")]
     [Tooltip("Is this final level of the World? the next World will be unlock")]
     public bool isFinishWorld;
 
     public int bullets = 10;        //bullets for player fire
     public int star1 = 100;            //score needed to reach 1 star
     public int star2 = 500;            //score needed to reach 2 star
     public int star3 = 1000;        //score needed to reach 3 star
     [Header("")]
     public AudioClip soundSuccess;    //sound played when level complete
     public AudioClip soundFail;        //sound played when fail
 
     public static GameManager instance;        //global call
 
     public enum GameState
     {
         Menu, Playing, Pause
     }
     [HideInInspector]
     public GameState state;
 
     private int score = 0;
     private int stars = 0;
     private int heart = 5;
 
     //Get Score from another script ex: int score = GameManager.Score;
     public static int Score{
         get{ return instance.score; }
         set{ instance.score = value; }
     }
 
     //Get Stars from another script
     public static int Stars{
         get{ return instance.stars; }
         set{ instance.stars = value; }
     }
 
     //Get Hearts from another script
     public static int Hearts{
         get{ return instance.heart; }
         set{ instance.heart = Mathf.Clamp(value,0,7); }
     }
 
     //Get Bullets from another script
     public static int Bullets{
         get{ return instance.bullets; }
         set{ instance.bullets = value; }
     }
 
     //Get Best of this level from another script
     public static int Best {
         get{ return PlayerPrefs.GetInt ("World" + GlobalValue.worldPlaying + GlobalValue.levelPlaying+"best", 0); }
         set{ PlayerPrefs.SetInt ("World" + GlobalValue.worldPlaying + GlobalValue.levelPlaying+"best", value); }
     }
 
     //Get BestStars of this level from another script
     public static int BestStars {
         get{ return PlayerPrefs.GetInt ("World" + GlobalValue.worldPlaying + GlobalValue.levelPlaying+"stars", 0); }
         set{ PlayerPrefs.SetInt ("World" + GlobalValue.worldPlaying + GlobalValue.levelPlaying+"stars", value); }
     }
 
     //Get Highest Level of this level from another script
     public static int HighestLevel {
         get{ return PlayerPrefs.GetInt ("World" + GlobalValue.worldPlaying + "HighestLevel", 1); }
         set{ PlayerPrefs.SetInt ("World" + GlobalValue.worldPlaying + "HighestLevel", value); }
     }
 
     //Get current state from another script
     public static GameState CurrentState{
         get{ return instance.state; }
         set{ instance.state = value; }
     }
         
     private PlayerController player;
 
     void Awake(){
         instance = this;
     }
 
     // Use this for initialization
     void Start () {
         state = GameState.Menu;
         player = FindObjectOfType<PlayerController> ();
 //        AdsController.HideAds();
     }
 
     // Update is called once per frame
     void Update () {
         
         if (Input.anyKeyDown && state != GameState.Playing)        //Start playing when hit anykey or any touch
             Play ();
     }
 
     //play game
     public void Play(){
         state = GameState.Playing;        //set state to playing
         player.Play ();        //call funstion Play() in player object
     }
 
     //called by another script by: GameManager.instance.GameSucess();
     public void GameSuccess(){
 //        AdsController.ShowAds();        //show admob
 
 //        if (ApplovinController.Instance != null)
 //            ApplovinController.Instance.ShowAds ();        //show applovin
 
         state = GameState.Menu;        //set state to Menu to stop player, enemy, monster,...because they only work when state = playing
         //check level pass
         if (GlobalValue.levelPlaying >= HighestLevel)
             HighestLevel = GlobalValue.levelPlaying + 1;    //if this level >= highest level then save next level number
 
         //check and save best score
         if (score > Best) {
             Best = score;
         
         //save best star of this level
             if (score >= star3 && BestStars < 3)
                 BestStars = 3;
             else if (score >= star2 && BestStars < 2)
                 BestStars = 2;
             else if (score >= star1 && BestStars < 1)
                 BestStars = 1;
         }
         MenuManager.instance.ShowLevelComplete ();        //Tell UI object show level complete panel
         SoundManager.PlaySfx (soundSuccess);        //play success sound
 
         //Unlock New World
         if (isFinishWorld) {
             int WorldReached = PlayerPrefs.GetInt ("WorldReached", 1);
             if (WorldReached == GlobalValue.worldPlaying)
                 PlayerPrefs.SetInt ("WorldReached", GlobalValue.worldPlaying + 1);
         }
     }
 
     //called by another script by: GameManager.instance.GameOver();
     public void GameOver(){
 
 
         if (state == GameState.Playing) {    //only work when in playing mode, to prevent duplicate calling
             state = GameState.Menu;        //set state to Menu to stop player, enemy, monster,...because they only work when state = playing
 //            MenuManager.instance.ShowGameOver ();    //Tell UI object show Game Over panel
             StartCoroutine(Restartcheckpoint(2));
             SoundManager.PlaySfx (soundFail, 0.5f);        //play fail sound
             player.Dead ();        //Tell player operate Dead() function
 
 //            AdsController.ShowAds();        //show admob
 
             //        if (ApplovinController.Instance != null)
             //            ApplovinController.Instance.ShowAds ();        //show applovin
         }
     }
 
     IEnumerator Restartcheckpoint(float time){
 
         yield return new WaitForSeconds (time);
         SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
     }
 }
 



please help me

unity-1.png (32.1 kB)
Comment
Add comment · Show 1
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 PizzaPie · May 25, 2017 at 08:42 PM 0
Share

You have somewhere another File/class named Game$$anonymous$$anager both declared inside the same namespace global (which is the default name space for classes without a specified namespace). To fix it either remove/delete one of them or put at least one on a different namespace.Cheers.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by zakaria92 · May 25, 2017 at 10:49 PM

Thank you for the solution

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 RowanG1 · Jan 29, 2018 at 01:45 AM 0
Share

The problem normally happens when you drag and drop a script to another folder, while your text editor still has the script open. When you save the file in text editor, the file is re-created in old location, so you have two versions.

avatar image
0

Answer by rlsmall · Oct 26, 2019 at 02:26 PM

In my case I saw the GmeManager Gear in the assets folder and I wanted to keep all scripts in the Scripts folder so I moved it there. But as Zakaria92 points out Unity automatically recreated the GameManager script in Assets so I had 2. Thanks zakaria92.

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

Answer by HernandoNJ · Jun 24, 2020 at 03:50 PM

In my case I had this error

 Assets\Scripts\Shooting.cs(5,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'Shooting'

It was because I had 2 copies of the same script in different folders so, I deleted one copy.

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

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

I have a problem with Unity 0 Answers

Help Troubleshooting: "Cannot generate 9 slice most likely because the size is too big." 2 Answers

URGENT!!! unity scene please review this question!! 0 Answers

I can not start my unity secion 5 (service not available, try again later) 0 Answers

i have problem when opening project 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