목록유니티/유니티 기능 (12)
A-Dyu의 개발 일기장

유니티의 인스펙터 창에서 컴포넌트의 함수를 실행시키고 싶을 때가 있습니다.그럴 때 실행시키고 싶은 메서드에 ContextMenu 어트리뷰트를 추가해 인스펙터 창에서 실행시킬 수 있습니다.using UnityEngine;public class Test : MonoBehaviour{ [ContextMenu("Do Something")] private void DoSomething() { Debug.Log("Invoke this function"); }} 이후 유니티에 들어가 컴포넌트의 메뉴를 열면 ContextMenu의 생성자의 인수로 넣은 Do Something이 메뉴에 추가되었습니다.실행시키면 로그에 정상적으로 출력이 되는걸 확인할 수 있습니다.컴포넌트의 메서드를 실행시..
유니티 기본 폰트를 가져오고 싶을 때가 있다.그럴 때 사용하는 것이 Resources.GetBuiltinResource메서드다.using UnityEngine;public class Test : MonoBehaviour{ Font Font; private void Awake() { //유니티 기본 폰트 가져오기 //타입을 인자로 가져오기 Font = (Font)Resources.GetBuiltinResource(typeof(Font), "LegacyRuntime.ttf"); //제네릭 메서드로 가져오기 Font = Resources.GetBuiltinResource("LegacyRuntime.ttf"); }}
유니티에서 기본적으로 제공하는 shape은 Cube, Sphere, Capsule등 여러가지 있다.이런 도형들을 런타임 시점 때 생성할 수 없을까?정답은 GameObject.CreatePrimitive 메서드를 사용하면 된다.using UnityEngine;public class Test : MonoBehaviour{ void Update() { //Sphere 생성 GameObject.CreatePrimitive(PrimitiveType.Sphere); //Cube 생성 GameObject.CreatePrimitive(PrimitiveType.Cube); //Capsule 생성 GameObject.CreatePrimi..
유니티에서 UI를 클릭할 떈 마우스 입력을 받지 않아야 할 때가 있다. 그럴 때 EventSystem의 IsPointerOverGameObject메서드를 쓰면 된다.IsPointerOverGameObject는 EventSystem object위에 있다면 ture를 반환한다.using UnityEngine;using UnityEngine.EventSystems;public class Test : MonoBehaviour{ void Update() { //UI 위에 마우스가 올려져 있다면 ture Debug.Log(EventSystem.current.IsPointerOverGameObject()); }} IsPointerOverGameObject는 인자로 pointe..