- Home /
Accessing RectTransform Rotation?
Heya,
I'm trying to get the Z rotation of a RectTransform on an UI element.
Let's say I put the rotation of said UI element RectTransform to (0, 0, 240) in the Inspector. Let's say I for example try to access the z rotation through script like so:
float zRotation = UIElementGameObject.GetComponent<RectTransform>().rotation.z;
but this always returns something close to 0. It seems to be accessing the 'normal' Transform rotation on the GameObject instead of the RectTransform rotation.
I can't seem to find a property that would give me access to the RectTransform rotation. Is there such a thing? Seems like an oversight if not.
Thanks!
Answer by ecv80 · Nov 26, 2018 at 10:52 PM
That's because you're getting the Quaternion rotation, which is different from the euler angle rotation (the one shown in the inspector).
float zRotation = UIElementGameObject.GetComponent<RectTransform>().eulerAngles.z;
should give you the value you expect.
Thank you. I thought I was missing something simple. Long day, don't ask. Cheers for the help!
Hahah it happens. Cheers and thanks for selecting the answer :)
Your answer
Follow this Question
Related Questions
How do I scale the Xmax value of a RectTransform 3 Answers
Unity 2D not rendering images in Canvas 1 Answer
Check if rotated UI are overlapping based on Rotation.Z 0 Answers
Converting to "Rect Transform" permanently deleted part of my project 0 Answers
How to find the bottom position of a Image based on it's height? 2 Answers