농장/Unity·C#

Unity get rect size

귤발자 2021. 5. 30. 19:48
728x90
반응형

https://dreamaz.tistory.com/1118

 

유니티에서 게임 오브젝트 폭, 높이 구하는 방법(How to get width, height of GameObject in Unity)

안녕하세요. 드리머즈입니다. 오랜만에 프로그래밍 관련 포스팅을 쓰네요. 자료 보관을 위해 기록 남깁니다. 유니티에서 GameObject의 Width와 Height를 구하려고 구글, 네이버를 뒤져봤지만.. 아무리

dreamaz.tistory.com

 

 

이 자체가 변수값인듯 하다. 대신 해당 스크립트 파일이 지정된 게임 오브젝트에 대한 Rect값을 가져온다.

GetComponent.<RectTransform>().rect.width
GetComponent.<RectTransform>().rect.height

 

 

공식 문서 예시

HingeJoint hinge = gameObject.GetComponent( typeof(HingeJoint) ) as HingeJoint;

 

Start()함수에서 또는 Awake()함수에서 미리 할당해놓아야 함.

 

Script명이 타입명이 될 수도 있다. 대신 같은 컴포넌트에 지정되어 있어야 하는 것 같다.

 

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=wjsdldks&logNo=220379134983 

 

[Unity] GetComponent 관련 함수

GetComponent 관련 함수 this.gameObject.GetComponent<컴포넌트타입>() 자신의 게임오브젝트에...

blog.naver.com

 

 

 

728x90
반응형