Orbiting an object with the camera doesn`t work properly

Hello,
I want to rotate my camera around an object while the object can rotate by itself.
Rotating my camera before the object rotated works fine but when the object has already rotated the rotation gets messed up.

This is my code so far:

void OrbitCamera()      //rotate the Camera
    {
        if(Input.GetMouseButtonDown(1) == true)
        {
            lastMousePos = Input.mousePosition;
        }
        if(Input.GetMouseButton(1) == true) //right Mousebutton pressed?
        {
            Vector3 currentMousePos = Input.mousePosition;

            Vector3 mouseMovement = currentMousePos - lastMousePos;     //the Movement of the Mouse
            Vector3 posRelativeToRig = TheCamera.transform.localPosition;
            Vector3 rotationAngles = mouseMovement / OrbitSensitivity;

            if(HoldToOrbit)
            {
                rotationAngles *= Time.deltaTime;
            }
            //Quaternion theOrbitalRotation = Quaternion.Euler( rotationAngles.y, rotationAngles.x, 0);

            //posRelativeToRig = theOrbitalRotation * posRelativeToRig;

            TheCamera.transform.RotateAround(cameraRig.position, TheCamera.transform.right, -rotationAngles.y);
            TheCamera.transform.RotateAround(cameraRig.position, TheCamera.transform.up, rotationAngles.x);

            Quaternion lookRotation = Quaternion.LookRotation(- TheCamera.transform.localPosition);
            TheCamera.transform.rotation = lookRotation;

            if(HoldToOrbit == false)
            {
                lastMousePos = currentMousePos;
            }
        }
    }

I would appreciate any help.
Thanks!

Is your camera a child of the Object you are trying to rotate?

I would have my object hierarchy in the scene like that to solve your problem:

-Root_Object
-----Camera
-----OtherRotationObject

So both Camera and OtherRotationObject are a child of an (empty) GameObject.
With that, you should be able to manipulate the rotation of the camera without affecting the rotation of the OtherRotationObject and visa vera.

My hierachy looks like this:
-Root_Object
-----Camera_Rig
---------Camera

because I want to move the Camera_Rig relative to the Root_Object so that I can change the position which the camera is rotating around.