목차

반응형

문제

유니티에서 게임 오브젝트에 스크립트를 드래그해서 컴포넌트로 추가할 때 아래와 같은 오류 메시지가 발생

Can't add script component 'TestScript' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

또는

Can't add script behaviour TestScript ,Can't Add Script The script needs to derive from MonoBehaviour!

 

원인

유니티를 공부하는 분이 이 에러 때문에 막히고 있어서 직접 봐보았더니 스크립트명과 스크립트의 클래스명이 달라서 생기는 문제였다.

스크립트 파일 이름과 스크립트에서 구현되어 있는 클래스의 이름이 다르면 컴포넌트로 인식을 못해서 불러오지 못한다.

 

해결

스크립트나 파일명을 하나로 통일한다.

위의 경우 파일명은 TestScript고 스크립트에서 클래스 이름은 Test인데 클래스 이름을 TestScript로 바꾼다.

정상적으로 처리되었다면 다음과 같이 Add Component에서 추가한 컴포넌트가 보인다.

 

반응형