멤버 변수를 public으로 해두고 유니티 인스펙터 상에 보이지 않게 하려면 아래 코드와 같이 [HideInInspector]를 추가해 주면 된다. public class Player : MonoBehaviour { public static Player instance { get; private set; } [HideInInspector] public PlayerAnimation m_Animation; [HideInInspector] public PlayerStats m_Stats; [HideInInspector] public PlayerHealth m_Health; [HideInInspector] public PlayerInput m_UserInput; [HideInInspector] public Pl..
게임 플레이어를 프리팹으로 만들고, 게임 플레이어는 여러가지 컴포넌트들이 아래와 같이 붙어있다. 이렇게 기능 별로 만들어 두어야 컴포넌트 조립이 수월해진다. 예를 들자면, 적 캐릭터에 붙일 수 있는 컴포넌트들이 있겠다. Character Controller : 유니티에서 기본적으로 제공하는 캐릭터 컨트롤러 Player : 최상위 클래스에 아래의 컴포넌트들을 가지고 있을 수 있다. Player Movement Weapon Handler Player Stats Player Inventory Player Outline Effect Player Footstep Sound Grenade Handler Player Input Head Bobber 보다 자세히 보려면 아래 링크의 프로젝트를 열어보면 되겠다. http..
GameObject.Find() 보다 빠르겠다. 태그로 검색하니까. 참고 문서 https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html Unity - Scripting API: GameObject.FindGameObjectsWithTag Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close do..
지금까지는 아래 코드와 같이 billboard를 직접 구현해서 썻는데 검색해 보니까 billboard renderer 라는 컴포넌트가 있더라! public class CameraFacingBillboard : MonoBehaviour { private Camera m_Camera; private Transform m_Transform; private void Awake() { m_Camera = Camera.main; m_Transform = transform; } void Update() { m_Transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward, m_Camera.transform.rotation * Ve..
구글링을 해보았더니, 나와 똑같은 의문을 가진 개발자가 있었다. 유니티 포럼에서도 여러 의견이 나뉘는데, 내가 봤을 때는 1 => 2 => 3 순으로 느리다. 따라서 유니티 인스펙터에 컴포넌트를 걸어두고 사용하자! 참고 문서 https://docs.unity3d.com/ScriptReference/Transform.GetChild.html Unity - Scripting API: Transform.GetChild If the transform has no child, or the index argument has a value greater than the number of children then an error will be generated. In this case "Transform child o..
아래 코드와 같이 Camera.main을 매번 호출할 필요는 없다. Start()에서 미리 Camera.main을 Camera 변수에 담아놓고 다른 함수에서 불러쓰는 것이 좋겠다. 성능 상 큰 문제는 아니지만, 성능을 고려하자면 캐싱해 놓고 써야겠다. public class Example : MonoBehaviour { //This is Main Camera in the Scene Camera m_MainCamera; //This is the second Camera and is assigned in inspector public Camera m_CameraTwo; void Start() { //This gets the Main Camera from the Scene m_MainCamera = Camer..