Stop Z rotation of gameObject on touch in Unity

Hi am trying to Rotate the gameobject in X-axis and Y-axis on touch, the code works perfectly, but it effects z-rotation also, I don’t want Z-Rotation, My gameObject does not contain Rigid-body so i can’t apply Z-rotation constraints. I have searched the problem on internet but can’t get any appropriate solution. Any help would be appreciated. Thankx

Here is my code:

public class Rot : MonoBehaviour {
    private float RotateSpeed   = 10f;

    void OnMouseDrag () {
        float xRot = Input.GetAxis ("Mouse X") * RotateSpeed * Mathf.Deg2Rad;
        float yRot = Input.GetAxis ("Mouse Y") * RotateSpeed * Mathf.Deg2Rad;

        transform.RotateAround (Vector3.up, -xRot);
        transform.RotateAround (Vector3.right, yRot);    
    }
}

Is this better?

public class Rot : MonoBehaviour
{
    private float RotateSpeed = 10f;

    void OnMouseDrag()
    {
        float xRot = Input.GetAxis("Mouse X") * RotateSpeed;
        float yRot = Input.GetAxis("Mouse Y") * RotateSpeed;
        transform.Rotate(Vector3.up, -xRot, Space.Self);
        transform.Rotate(Vector3.right, yRot, Space.World);
    }
}

You are trying to use a deprecated rotation function, just use the latest.

Also, what you are trying to do is not simple. It may seem like it should work out such that the Z-axis rotation goes unchanged. But that is not the case. Look here:

link stackExchange article about this

I used the simple fix mentioned in the article and the results are OK. Would maybe even fit the bill for you if you detected when the object was “upside down” so you could change the sign on the rotation about the up axis.