Quaternion.AngleAxis

I was tinkering a bit with the MouseLook.cs from the Unity StandardAssets.

They have some code that uses Quaternion.AngleAxis, more specifically:

Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);

What I need to do is if I have the xQuaternion, what sort of math would I have to do to get the rotationX instead of the xQuaternion. In other words, how would I do the reverse of this line of code. What I need to do, is I am using this code to move my camera, and I am sometimes switching to another camera mode which can also move the camera around. When I switch back however, I want to set the values of rotationX and rotationY to be the new rotation of the camera so that the camera doesn’t “jump” back.

You can use its inverse function, Quaternion.ToAngleAxis:

var angle: float; // the variables must exist, because they will
var axis: Vector3; // be passed by reference (result stored in them)
xQuaternion.ToAngleAxis(angle, axis);

or in C#:

float angle;
Vector3 axis;
transform.rotation.ToAngleAxis(out angle, out axis);

SIDENOTE: A quaternion is a math representation of a single rotation of some angle about an arbitrary axis, thus converting from and to the angle-axis format is always possible.