안녕하세요 로로아빠입니다.
오늘은 유니티 코드에서 삭송관계를 해제하는 방법입니다.
해결방법
transform.DetachChildren
Transform.Parent
예제소스
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour{
void Awake(){
transform.DetachChildren();
Destroy(gameObject);
}
}
위 코드는 부모만 제거하고 자식들은 유지하기 원하는 경우 사용할 수 있습니다.
Transform.Parent 는 부모를 변환합니다.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform cameraTransform = Camera.main.transform;
void Awake() {
cameraTransform.parent = transform;
cameraTransform.localPosition = -Vector3.forward * 5;
cameraTransform.LookAt(transform);
}
}
또는 transform.parent = null;로 사용할 수 있습니다.
감사합니다.
'IT팁 > IT 기타' 카테고리의 다른 글
[Unity3D] 이미지 파일 텍스쳐에 넣기 (0) | 2023.01.22 |
---|---|
Google chart Spring 구글 차트에 서버 데이터 넣기 (0) | 2023.01.20 |
[해결] The JRE could not be found. Edit the server and change the JRE location (0) | 2023.01.20 |
[Websquare] Websqure 가 정의 되지 않았습니다 (0) | 2023.01.20 |
[공유] VI 에디터 사용법 (0) | 2023.01.18 |