condition transform Rotation not working ?

hello

i was try to do this but not working

public Transform GearTransform;

and

 if (GearTurnTarget.transform.rotation.z > -90)
                        {
                            GearTurnTarget.transform.Rotate(Vector3.back, SpeedTurn * Time.deltaTime);
                            print("1");

                        }
                        else
                        {
                            print("2");

                        }

but its not working and I tried something like this

 if (UnityEditor.TransformUtils.GetInspectorRotation(GearTurnTarget.transform).z > -90)
                        {
                            GearTurnTarget.transform.Rotate(Vector3.back, SpeedTurn * Time.deltaTime);
                            print("1");

                        }
                        else
                        {
                            print("2");

                        }

and its working But I think it only works in UnityEditor only so what is my mistake

thank you

GearTurnTarget.transform.rotation represents quaternion, and Z component of the quaternion takes values from the range -1…1. But you want it to be euler angle representation of the rotation. So try this:

if (GearTurnTarget.transform.eulerAngles.z > -90)

The way it works in UnityEditor is that UnityEditor.TransformUtils.GetInspectorRotation(GearTurnTarget.transform) returns Vector3, which is euler representation, not quaternion.

GearTurnTarget.transform.Rotate(Vector3.back, SpeedTurn * Time.deltaTime); Looks really wierd. Check this out: Unity - Scripting API: Transform.Rotate