대왕휴지의 개발 공부

[Unity] 인스펙터에 있는 회전 값을 그대로 얻는 법 본문

Unity

[Unity] 인스펙터에 있는 회전 값을 그대로 얻는 법

대왕휴지 2022. 11. 6. 00:01

https://forum.unity.com/threads/solved-how-to-get-rotation-value-that-is-in-the-inspector.460310/

 

[SOLVED] How to get "Rotation" value that is in the inspector?

Is there a direct way to get the value that are in the Rotation field of the inspector? I need that angle that is in the inspector. for example...

forum.unity.com

인스펙터에 있는 값을 그대로 얻기는 어렵다.

만약 인스펙터에 Local 좌표의 x에 음수값 -90도가 있다면

우리가 스크립트로 얻을 수 있는 x의 값은 270이다.

이 코드를 보자

이 코드의 WrapAngle함수는 음수값을 만들어주는 함수이다.

270에 -360을 해주니 -90이 잘 나온다.

인스펙터에 있는 음수값이 그대로 나온 것이다.! 

 

암튼 인스펙터처럼 음수 값을 얻기 위해서 angle이 180이 넘어가면

360도를 빼주어서 음수값을 얻으면 된다!