How stop Z value being effected when rotating X and Y only (C Sharp)?

Hi Everyone,

I’m trying to rotate camera(X and Y only), but Z value is also being effected.
Here’s the script that I’m using.

if(Input.touchCount > 0){

   my_Touch = Input.GetTouch(0);

   if(Input.GetTouch(0).phase == TouchPhase.Moved){
   
    Camera.main.transform.Rotate(my_Touch.deltaPosition.y * rotationSpeed, my_Touch.deltaPosition.x * rotationSpeed,0);
   }
}

I also tried this but didn’t work : Problem with Z rotation when rotating X and Y and the same time. - Unity Answers

You shouldn’t use Unity’s transform methods for specific behaviors like this. Instead, create a Vector3 representing a euler rotation and change it manually. Then you can do transform.rotation = Quaternion.Euler(EulerRotation).

Edit:
Nevermind. transform.Rotate should work fine for your desires. Your code’s correct but are you sure the Z axis is the one you don’t want to rotate on?