-
MonoBehaviour는 관리되는 Object로, 직접 생성해서는 안된다.
//MonoBehaviourClass생성 //mb1 = new Cmb1(); 으로 생성하면 경고 발생. //경고: You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all UnityEngine.MonoBehaviour:.ctor () public class Cmb1 : MonoBehaviour { void Start() { } } //생성하여 사용하려는 곳. mb1 = gameObject.AddComponent<Cmb1>();
'Unity' 카테고리의 다른 글
Unity - 자식 GameObject에 있는 Component얻기 (0) 2021.03.25 Unity - Unity Editor 다중 실행(창 여러개 시행) (0) 2021.03.25 Unity - UI Button (0) 2021.03.25 Unity - Prefabs (1) 2021.03.25 Unity - Script Component얻기 (0) 2021.03.25 Unity - Vertex (0) 2021.03.22 Unity - 튜플 리턴 타입(tuple return type) (0) 2021.03.22 Unity - Renderer.material 수정 (0) 2021.03.21