set gameobject rotation unity code example

Example 1: how to just aet z rotation on transform unity

transform.rotation = Quaternion.Euler(0, 90, 0);

Example 2: unity clamp rotation

float rotationX = 0;
float rotationY = 0;
// you might also have some rotation speed variable
void Update() {
   rotationX += Input.GetAxis("Vertical") * Time.deltaTime;
   rotationX = Mathf.Clamp(rotationX, minRotationX, maxRotationX);
   rotationY += Input.GetAxis("Horizontal" * Time.deltaTime;
   transform.rotation = Quaternion.Euler(rotationX, rotationY, 0);
 }

Example 3: how to make the rotation of an object the same as another object in unity

Vector3 newRot = new Vector3 (otherObject.transform.eulerAngles.x, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
 transform.rotation = Quaternion.Euler (newRot);