Why Is My Camera Rotating About Zed?

Hello!

I’m trying to add functionality to control the player camera with the mouse. I only want the camera to use X and Y axis to rotate. However, I can see in playmode that my camera will rotate on the zed axis. I’m confused about this, because I haven’t asked it to fetch a value for zed in my rotation vector, and I actually tried to clamp it to 0. Any ideas why this is happening? Here is my entire script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cameraLOOK : MonoBehaviour {
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    float updownLOOK = Input.GetAxis("Mouse X");
    float leftrightLOOK = Input.GetAxis("Mouse Y");
    Vector3 lookdirection = new Vector3(-leftrightLOOK, updownLOOK, Mathf.Clamp(0.0f, 0.0f, 0.0f));
    gameObject.transform.Rotate(lookdirection);
}

}

@username

You are missing one thing you are adding rotation and and not cancelling rotation around z-axis.
so apply the rotation you want, then cancel out any Z rotation that got added in there.

using UnityEngine;

public class cameraLOOKScript : MonoBehaviour
{
    // Use this for initialization void Start () {
    private void Update()
    {
        var updownLook = Input.GetAxis("Mouse X");
        var leftrightLook = Input.GetAxis("Mouse Y");
        var lookdirection = new Vector3(-leftrightLook, updownLook, 0f);
        gameObject.transform.Rotate(lookdirection);
        var z = transform.eulerAngles.z;
        transform.Rotate(0, 0, -z);
    }
}