title: Unity, Quaternion.Euler, rotate only around Y axis
body: <p>I have my main camera in the scene:</p>
  
  <p><a href="https://i.stack.imgur.com/VKyze.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VKyze.png" alt="My camera"></a></p>
  
  <p>And I have this code that smoothly rotates the camera:</p>
  
  <pre><code>private IEnumerator SmoothlyRotateCamera()
  {
      float duration = 0.3f;
      Quaternion from = transform.rotation;
      Quaternion to = from * Vector3.up * 180f;
  
      float elapsed = 0.0f;
  
      while (elapsed &lt; duration)
      {
          transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
          elapsed += Time.deltaTime;
          yield return null;
      }
  
      transform.rotation = to;
  
      isRotating = false;
  
      yield return null;
  }
  </code></pre>
  
  <p>Currently, my camera's rotation is <code>[30, -60, 0]</code> and I want it to rotate around Y axis by 180 degrees.</p>
  
  <p>In theory, to achieve that I need to rotate it for <code>Vector3.up * 180f</code>, everything sound fine, except the fact, when I rotate it that way, it also rotates all other axes as well.</p>
  
  <p>If I rotate it by <code>new Vector3(180f, 0f, 0f)</code> - only X axis will be affected.</p>
  
  <p>If I rotate it by <code>new Vector3(0f, 0f, 180f)</code> - only Z axis will be affected.</p>
  
  <p>And if I rotate it by <code>new Vector3(0f, 180f, 0f)</code> - all of the axis will rotate as well.</p>
  
  <p>I've checked the rotation by setting my X rotation to 0, so now my camera's rotation is <code>[0, -60, 0]</code> and if I rotate it the way it intended to be, by <code>Vector3.up * 180f</code>, then everything works fine! BUT, I need my camera's X to stay in the place. E.g., rotation in the Editor itself only by Y gives me the result that I want.</p>
  
  <p>What should I do? How do I rotate it by 180 degrees by Y axis only?</p>
  
  <p>P.S. I know about <code>transform.Rotate</code> but in my case I need to rotate it using the way that I have described here.</p>
  
  <p>Thanks!</p>