Rotate a cube using touch inputs

Hi, I’m trying to discover how to use touch inputs properly. I have read some pages on the unity manual and some forums as well but then, when I go to unity, things works unexpectedly.

I want to be able to rotate a cube (on Y axis) sliding my fingers on the screen of a mobile device so I made use of touch phases, comparing touch positions and that, but I have some undesirable behaviours like “Insta Rotating” the moment a finger touches the screen and also some shakes on the cube rotation at the end of the movement when the finger is not moving anymore but it is still touching the screen.

I have a line of code that rotates the cube on Y axis using the mouse which works perfectly for me:

private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            transform.Rotate(0, Input.GetAxis("Mouse X") * camRotationSensitivity * Time.deltaTime, 0);
        }
     }

I pretty much want the same behaviour but using touchs inputs.
If you have some advice to give me in this matter I would be grateful.

This code will work for touches exactly as it works for mouse if Unity - Scripting API: Input.simulateMouseWithTouches this flag is enabled.

Thanks! It works.