Error cs0101: the namespace already contains a definition for

  • by 공구리
  • 2018/10/16 15:03
  • haegonggun.egloos.com/6397834
  • 덧글수 : 0

the namespace global already contains a definition for '~' 에러가 뜰때가 있는데, 기본적으로 namespace가 충돌된다는 의미이다. Unity에서는 Assets 안에 코드에 대한 충돌을 모두 체크하는 듯 하니, 실제 drag한 코드 내부 뿐아니라 asset 다른 코드에서 충돌이 발생할 가능성이 있으므로, 이를 처리해주면 된다. 예를 들어 기존 프로젝트를 Import 하면서 Unity에서 자체적으로 Agent1.cs를 만들어주었을 경우, 기존 코드인 Agent.cs와 Agent1.cs 의 namespace가 충돌이 발생하게 된다. 따라서 Agent1.cs를 지우거나 하면 에러가 사라질 것이다.

추가적으로,  Unity script는 기본적으로 Asset 파일들끼리 충돌이 발생하면 그 에러를 처리하지 않고는 다른 warning이나 error도 처리되지 않는 것 같다.

포스트 메타 정보

퍼블리싱 및 추천

    퍼블리싱 및 추천 정보가 없습니다.

같은 카테고리의 글


주요 콘텐츠로 건너뛰기

이 브라우저는 더 이상 지원되지 않습니다.

최신 기능, 보안 업데이트, 기술 지원을 이용하려면 Microsoft Edge로 업그레이드하세요.

컴파일러 오류 CS0101

  • 아티클
  • 06/23/2022
  • 읽는 데 2분 걸림

이 문서의 내용

'namespace' 네임스페이스에 이미 'type'에 대한 정의가 포함되어 있습니다.

네임스페이스 에 중복 식별자가 있습니다. 중복 식별자 중 하나를 삭제하거나 이름을 바꿉니다. 자세한 내용은 네임스페이스를 참조하세요.

다음 샘플에서는 CS0101을 생성합니다.

// CS0101.cs namespace MyNamespace { public class MyClass { static public void Main() { } } public class MyClass // CS0101 { } }

클래스 이름이 네임스페이스 이름과 충돌할 때 CS0101도 생성됩니다. 이 문제는 네임스페이스 경로를 동일하게 유지하려고 하는 기본 클래스에 대한 도우미 클래스를 사용하여 확장할 때 발생할 수 있습니다. 아래 예제에서 UTF8 클래스는 분명히 String 클래스의 자회사여야 하지만, 해당 네임스페이스를 Utilities.String으로 선언하여 동일한 이름 공간으로 강제 적용하려고 하면 CS0101 오류가 발생합니다.

//CS0101-Utilities.String.cs namespace Utilities { public class String { public string MyString; } } //CS0101-Utilities.String.UTF8.cs namespace Utilities.String // CS0101 { public class UTF8 { public string MySecondString; } }

  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges

  • Home /

4

Question by Xdy · Jun 23, 2013 at 01:22 PM ·

error at line "public class ShooterGameCamera : MonoBehaviour {" this is upper part of script ShooterGameCamera.cs taken from 3rdpersonshooter unity demo game

using UnityEngine; using System.Collections;

// 3rd person game-like camera controller // keeps camera behind the player and aimed at aiming point public class ShooterGameCamera : MonoBehaviour { public Transform player; public Transform aimTarget; public float smoothingTime = 0.5f; public Vector3 pivotOffset = new Vector3(1.3f, 0.4f, 0.0f); public Vector3 camOffset = new Vector3(0.0f, 0.7f, -2.4f); public Vector3 closeOffset = new Vector3(0.35f, 1.7f, 0.0f); public float horizontalAimingSpeed = 270f; public float verticalAimingSpeed = 270f; public float maxVerticalAngle = 80f; public float minVerticalAngle = -80f; public float mouseSensitivity = 0.1f; public Texture reticle; private float angleH = 0; private float angleV = 0; private Transform cam; private float maxCamDist = 1; private LayerMask mask; private Vector3 smoothPlayerPos;

15

Answer by RalphTrickey · Jun 23, 2013 at 01:40 PM

It means exactly what it says. Somewhere in your source files (or a third party library) you have a class called ShooterGameCamera.

The simplest thing to do is to rename your class, although it may be worth finding out where else you have that class declared.

This reply helped me also. Thanks a lot

Your answer

Error cs0101: the namespace  already contains a definition for

Hint: You can notify a user about this post by typing @username

Attachments: Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

How do I fix global namespace error?

Just search the Project window for the script with the global namespace issue. This should reveal more than 1 copy of the offending script. To fix this, you'll want to delete or rename one of the script file's name, and the class definition.