UserManager와 StageManager를 만들었다.using System.Linq; using UnityEngine; public class WayPoint : MonoBehaviour { [SerializeField] private Transform[] wayPoint; private void OnValidate() { //본인을 제외하고 자식의 Transform만 가져온다. wayPoint = GetComponentsInChildren<Transform>(true) .Where(t => t != transform) .ToArray(); } public Transform[] GetWayPoint() { return wayPoint; } }
private void OnValidate() { /// <summary> OnValidate 관련 </summary> /// /// OnValidate는 에디터 함수이기 때문에 /// Find를 사용해도 빌드한 최종 결과물에는 영향을 주지 않음 /// 다만 너무 남용할 경우 오류가 생길 수 있으니 GetComponent정도만 사용할 것 wayPoint = GameObject.Find("WayPoint")?.GetComponent<WayPoint>(); }

GetComponentsInChildren문제웨이포인트를 받아오기 위해 GetComponentsInChildren<Transform>를 통해 자식들의 transforn 정보를 받아오려고 했는데, 막상 이 코드를 사용하니 자식뿐만 아니라 본인의 transform까지 가져오는 문제가 발생했다.
찾아봤지만 자식의 컴포넌트만 검색해 주는 메서드는 따로 없는 것 같아 결국 다음과 같은 방식으로 해결했다:
private void OnValidate() { //본인을 제외하고 자식의 Transform만 가져온다. wayPoint = GetComponentsInChildren<Transform>(true) .Where(t => t != transform) .ToArray(); }
GetComponentsInChildren<Transform>(true): 자식들의 트랜스폼을 모두 가져오는데 (true: 비활성화된 자식까지 포함)Where(t => t != transform): transform이 아닌 것들만 가져오고 (자신의 transform과 다른 값인 transform만 가져오고)ToArray(): 배열 형태로 반환하라
' 앞으로는 완벽하지 않더라도 당일에 TIL을 올릴 것.
왜냐하면 그게 TIL이니까…… '
오늘 혜진 님 TIL 읽다가 발견한 문구예요.
살아계시나요.