하참이의 아이디어노트

Unity troubleshooting (1) error CS0104: 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'System.Diagnostics.Debug' 본문

Unity

Unity troubleshooting (1) error CS0104: 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'System.Diagnostics.Debug'

하참이 2024. 11. 15. 16:11

 

유니티 게임 서버 관련 공부를 하다 생긴 오류이다.

 

직역하면 Debug가 모호하다는 내용이다.

 

에러 코드는 다음과 같다.

 

using DummyClient;
using ServerCore;
using System.Diagnostics;
using UnityEngine;

class PacketHandler
{
    public static void S_ChatHandler(PacketSession session, IPacket packet)
    {
        S_Chat chatPacket = packet as S_Chat;
        ServerSession serverSession = session as ServerSession;

        if (chatPacket.playerId == 1)
            Debug.Log(chatPacket.chat);
    }
}

 

 

위 코드를 실행하면 다음과 같은 오류가 나타남을 확인 할 수 있다.

 

Assets\Scripts\Packet\PacketHandler.cs(14,13): error CS0104: 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'Systehttp://m.Diagnostics.Debug'

 

본론부터 말하면 3행의 

 

using System.Diagnostics;

 

 

이 4행의

 

using UnityEngine;

 

 

와 겹쳐서 나는 오류이다. UnityEngine을 지울 수 없으니 3행을 지워 코드를 완성한다.

 

 

using DummyClient;
using ServerCore;
using UnityEngine;

class PacketHandler
{
    public static void S_ChatHandler(PacketSession session, IPacket packet)
    {
        S_Chat chatPacket = packet as S_Chat;
        ServerSession serverSession = session as ServerSession;

        if (chatPacket.playerId == 1)
            Debug.Log(chatPacket.chat);
    }
}

 

 

 

찾아보니 흔히 C#에서 서버 환경을 구현해놓고 Unity 환경으로 옮길 때 발생하는 오류인 것 같다. 검색하면 바로 나오는 내용이긴 하나 비슷한 오류와 자주 만날 수 있으니 알아두면 좋을 것 같다.

 

-- 참고 자료 --

 

https://stackoverflow.com/questions/62065650/ambiguous-reference-cs0104-debug-is-an-ambiguous-reference-betweenunityengin

 

Ambiguous reference CS0104: 'Debug' is an ambiguous reference between'UnityEngine.Debug' and 'System.Diagnostics.Debug'

I am new to programming and need help to fix error pop-up, which appeared after writing if statement in code, 5 error codes for all Debug.Log lines, before if statement they were working fine. ...

stackoverflow.com

 

 

https://www.youtube.com/watch?v=slGVc0fipI8

 

'Unity' 카테고리의 다른 글

유니티 실무 (1) - Drag And Drop  (0) 2024.03.05
Hello, Unity!  (0) 2023.07.18