# Unity transform.rotation not giving real value

i confused , when the object is at 0 rotation ( not rotated yet ) , it giving real value ( 0 ) , but when the object is rotated 180 degree , transform.rotation is giving false value ( 1 ) , this is the screenshot :

If the picture is not clear enough , go here https://i.stack.imgur.com/miWIE.png .

Then this is my script that debugged the code and rotate the object :

void RotateFlip() {
GameObject databasegameobject = GameObject.Find ("database");
database databasechange = databasegameobject.GetComponent<database>();
Debug.Log ("current object rotation is " + theiconarrow.transform.rotation.z + " degree ");
if (theiconarrow.transform.rotation.z == 0 ) {
theiconarrow.transform.Rotate (new Vector3 (theiconarrow.transform.rotation.x, theiconarrow.transform.rotation.y, 180), Space.World);
}

}

if (theiconarrow.transform.rotation.z == 180) {
theiconarrow.transform.Rotate (new Vector3 (theiconarrow.transform.rotation.x, theiconarrow.transform.rotation.y, 180), Space.World);
}
}
}


I don't understand why this thing happened , is this a kind of bug or what ?

I am sorry if this already asked somewhere , but i just don't know how to find it at search engine ( neither here ) .

Extra question ( optional ) : is there any application to build app with easy coding and not an game engine ?

• Unity stores rotations as quaternions (see the doc) with every component in the range -1.0 to 1.0 - see this question for more details – UnholySheep Jan 11 '17 at 8:45
• then what should i use to get the current rotation ? – user6668201 Jan 11 '17 at 8:47
• As suggested in the answer you could use transform.eulerAngles instead. Or learn how to work with quaternions - both are valid options – UnholySheep Jan 11 '17 at 8:49

Unity, like many 3D softwares uses Quaternions to deal with rotation (prevent the Gimbal Lock problem). You get a quaternion when you call theiconarrow.transform.rotation (a quaternion is represented by 4 values : x, y, z, w, but are not really the angles around the 3 axis with an additional value).
However, because quaternions are not easily readable by humans, the inspector shows you the euler angles (pitch, yaw, roll) of the rotation (which are the angles around the 3 unit axis). In your code, you can get the euler angles by calling : theiconarrow.transform.eulerAngles.