Unity3D
[Unity] transform.root.GetComponentInChildren<Canvas>() | How do you get the parent canvas?
DragonTory
2022. 12. 24. 00:03
반응형
How do you get the parent canvas?
Top Canvas 찾기 :
Unity Editor 말고 Script에서 UI가 적용 되고 있는 최상위 Canvas를 코드로 찾을 때 아래 메소드를 사용 할 수 있습니다.
transform.root.GetComponentInChildren<Canvas>();
var topCanvas = transform.root.GetComponentInChildren<Canvas>();
추가적으로 Canvas 프라퍼티 중에
canvas.isRootCanvas
canvas.rootCanvas
위와 같은 것도 활용 할 수 있습니다.
최상위 Canvas를 찾은 다음
CanvasGroup 컴포넌트가 결합된 캔버스라면
Alpha 값이나 Interactable 같은 것으로 FadeIn FadeOut이나
전체 입력을 편하게 막을 수도 있습니다.
반응형