Rotating object in script

I am trying to rotate on object in script, but it acts very strange. If I try to rotate x by 10 degrees, it rotates everything but x 180 degrees, but when I Rotate z, it just rotates z by 180, not 10.
Here is my code:

Quaternion qt = new Quaternion (10, 0, 0, 0);
tf.rotation = qt;

Why isn’t it rotating correctly?

You could do this instead:

Quaternion qt = Quaternion.Euler(x,y,z);
 tf.rotation = qt;

Rotations can be represented as a Quaterion, with (w, x, y, z components) and Euler (x, y, z components). The rotation you see in unity’s inspector and the one you will use almost all of the time are Euler. However Quaternions are generally better for the backend stuff so rotations are stored as Quaternions.

To go from a Euler rotation to a Quaternion use Quaternion.Euler, i.e.

Quaternion qt=Quaternion.Euler(10, 0, 0);
tf.rotation=qt;

To go from Quaternion to Euler use Quaternion.eulerAngles, i.e.

Quaternion qt=transform.rotation;
Vector3 eul=qt.eulerAngles.

Generally you can use Transform.eulerAngles to skip Quaternions and make your code more understandable, i.e.

transform.eulerAngles=new Vector3(10, 0, 0);

and

Vector3 rotation = transform.eulerAngles;

Since it is relevant here, Quaternions are useful if you want to rotate a rotation. Just use Quaternion*Quaternion and you’ll get the first rotation rotated by the second rotation. i.e.

Quaternion combinedRot=Quaternion.Euler(0, 90, 0)*Quaternion.Euler(90, 0, 0);

returns a rotation which is a rotation of 90 degrees along the y axis followed by a rotation of 90 degrees along the x axis.

However if you are rotating transform then you should just change the rotation of a transform it’s easier to understand i.e.

transform.Rotate(90, 0, 0);