Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question I'm so confused

Discussion in 'Scripting' started by TrexMatrix, Aug 14, 2023.

  1. TrexMatrix

    TrexMatrix

    Joined:
    Aug 8, 2023
    Posts:
    39
    I came across this error even though I'm pretty sure nothing is wrong with my script.

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

    This is the script:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class MainMenu : MonoBehaviour
    8. {
    9.     public void PlayGame()
    10.     {
    11.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    12.     }
    13.  
    14. }
    15.  
     
  2. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    contains a definition errors sometimes mean one already exists. Check through your assets, and make sure you don't have another MainMenu.cs
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,977
    You have another mainmenu script somewhere.
     
    Bunny83 likes this.
  4. TrexMatrix

    TrexMatrix

    Joined:
    Aug 8, 2023
    Posts:
    39
    thx i didnt think of that