Object Rotation Transform

Sorry for the simple question, but this is making me mad now.

I wish to change a gameobjects, transform, rotation.

Simply:

transform.rotation.z = 45;

No rotaion speed values, just a simple way to access the z and change it with another variable;

Thanks James

transform.rotation is a 4 part quaternion (w, x, y, z). 99% of the time you’ll want to change the rotation as a 3 part euler rotation (x, y, z). i.e.

Vector3 oldRot = transform.eulerAngles;
transform.eulerAngles = new Vector3(oldRot.x, oldRot.y, 45);

or

Vector3 oldRot = transform.rotation.eulerAngles;
transform.rotation= Quaternion.Euler(oldRot.x, oldRot.y, 45);

The values displaying in the inspector are the local values while rotation and eulerAngles are world rotation. If you want to get/set the local rotation user localEulerAngles instead of eulerAngles and localRotation instead of rotation.