Middle mouse camera rotate around Y-axis

This may be a fairly easy one to solve, but it may not (couldn’t find answers online, could have been because of my method. I am not interested in using outside assets). I am trying to make the third person camera for my character. I got zooming working well and easy (with constraints too), although my problem is with rotation. Rotating left/right , and up/down, work fine on their own. But when both are activated, it causes odd problems and difficulties in controlling the camera.

(I cut out a bit of the useless pieces of the scripts to make it easier to read)

rotateSpeed = 225

    void RotateControl()
    {
        if (Input.GetMouseButton(2))
        {
            transform.RotateAround(parent.transform.position, Vector3.up, Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime);
            transform.RotateAround(parent.transform.position, Vector3.left, Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime);
        }
    }

Never used Tranform.RotateAround

I prefer different approach:

public float SensitivityX;
public float SensitivityY;
public float TargetAngleX;
public float TargetAngleY;

void Update () {

    if (Input.GetMouseButton (2)) {
    TargetAngleX += Input.GetAxis("Mouse X") * SensitivityX * Time.deltaTime;
    TargetAngleY += Input.GetAxis("Mouse Y") * SensitivityY * Time.deltaTime;
    
    // Make limits on vertical rotation
    TargetAngleY = Mathf.Clamp (TargetAngleY, -90 , 90);
    
    transform.eulerAngles = new Vector3 (TargetAngleX , TargetAngleY, 0);
    }
}

Problem here is that after you rotate on other axis the other one will be on angle too. This little bit depends where you are going to use it, but I would do it like this:

public Transform rotate;
public Transform tilt;
public float rotateSpeed;

void Update()
{
    if (Input.GetMouseButton(2))
    {
        tilt.Rotate(Vector2.up * Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime);
        rotate.Rotate(Vector2.left * Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime);
    }
}

83967-rotatetilt.png

Then just move Tilt to move your camera.