- Home /
How to get inspector rotation values ?
Hi, In my app i assembly some car parts and i want to check if the rotation of my object is right. Here are parts of my code:
private void Update() { Debug.Log("x: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.x)); Debug.Log("y: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.y)); Debug.Log("z: " + Helper.WrapAngle(gameObject.transform.localEulerAngles.z)); }
My WrapAngle:
public static float WrapAngle(float angle) { angle %= 360; if (angle > 360) return angle - 360; return angle; }
I get something like this:
I want to get the same values as the Inspector rotation. Is it possible ? Thank you!
Answer by tocu-adrian · Jan 11, 2019 at 12:04 PM
I found a solution:
var x = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).x; var y = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).y; var z = UnityEditor.TransformUtils.GetInspectorRotation(gameObject.transform).z; Debug.Log("x: " + x); Debug.Log("y: " + y); Debug.Log("z: " + z);
I get what i want with this.
Yo thank you so much for this. I have been looking for it for hours. And they all keep talking about how you should understand quaternion to do it
Its not working when I build the game. I want to use these values in my game.
This solution is using "UnityEditor" namespace. This namespace works only in Unity Editor and will not work in a builded game.
Answer by haruna9x · Jan 11, 2019 at 11:52 AM
Let's review: 1. You are using the local rotation of the object, while Inspector is displaying the rotation of the object's world.
WrapAngle as I see it doesn't seem to work as you want.
I wrote it before:
public static float Clamp0360(float eulerAngles)
{
float result = eulerAngles - Mathf.CeilToInt(eulerAngles / 360f) * 360f;
if (result < 0)
{
result += 360f;
}
return result;
}
Your answer
Follow this Question
Related Questions
Rotation angles not corresponding (inspector, debugging) 0 Answers
Rotation losing precision 0 Answers
Why is my transform.rotatearound reset only working on positive Y? 0 Answers
Whats the Difference Between Rotation EulerAngles and Quaternions? 2 Answers
How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers