Need help making a camera script

This is a short question, how can I improve the camera script, I do not need a wiki page about, just edit the piece of code as I have seen it (and it is way too complicated for me to understand).

        if (CamX < 0)
        {
            Camera.transform.Rotate(0, -1, 0);
        }
        if (CamX > 0)
        {
            Camera.transform.Rotate(0, 1, 0);
        }
        if (CamY > 0)
        {
            Camera.transform.Rotate(-1, 0, 0);
        }
        if (CamY < 0)
        {
            Camera.transform.Rotate(1, 0, 0);
        }

PS. I know using a bunch of if’s is messy, but if I make it else if then it goes messy, you’ll know why. Sorry for the laggy video quality if it is like 2 fps, I hope you can tell what is wrong with camera.

A way to prevent that from happening is to always set the target rotation, not apply some rotation for every small change. I believe (?) the problem here has to do with the accumulation of small imprecisions or something like that.
This code should do what you want it to:

//In Update()
Vector2 mouseInput = new Vector2(Input.GetAxisRaw("Mouse Y"), Input.GetAxisRaw("Mouse X"));
mouseDelta += mouseInput; // mouseDelta being a Vector2 defined outside of Update()
transform.eulerAngles = new Vector3(-mouseDelta.x, mouseDelta.y, 0);

You may wanna lock the rotation to some range tho.

Thanks a bunch! It still has minor problems but I am sure I can get those fixed.

I only did quick testings. If you still need help, please tell me/us what problems are left after you tried fixing them.

Alright, I’ll be making a thread about some other stuff with the camera unrelated with this just to let you know.