How to get the Z - Axis of the Cam


i have this line in my code:

transform.rotation = Quaternion.Slerp(transform.rotation,cam.transform.rotation, 0.1f);

i need only the z axis of my code so logically something like this cam.transform.rotation.z.
sadly this doesnt work. any suggestions on how to do it?

cameraZRotation = Quaternion.Euler(0, 0, cam.transform.rotation.eulerAngles.z);

I’m sure there’s a cleaner way to do this without switching back to Euler angles but my math is rusty and well… Whatever works until performance is not an issue!

(Note: I just used that to restrict camera rotation around Y in a small practice project, see here with source code linked)

Try this float CameraZRotation = CameraTransform.rotation.z