Camera resets when screen is re-touched

I modified a standard mouse orbit script to work with my current scene. When I’m playing it on the PC, everything works fine. however, when I put it on Android I am initially able to orbit correctly, but if I take my finger off, then put it back on the screen the camera position completely resets itself.

Any ideas?

using UnityEngine;
using System.Collections;

public class CameraMove : MonoBehaviour {
public Transform target;
public float distance= 10f;
public int cameraSpeed= 5;
 
public float xSpeed= 175.0f;
public float ySpeed= 75.0f;
 
public int yMinLimit= 10; //Lowest vertical angle in respect with the target.
public int yMaxLimit= 80;
 
public float minDistance= .5f; //Min distance of the camera from the target
public float maxDistance= 1.5f;
 
private float x= 0.0f;
private float y= 0.0f;
 
void  Start (){
    Vector3 angles= transform.eulerAngles;
    x = angles.y;
    y = angles.x;
 
   // Make the rigid body not change rotation
      if (rigidbody)
      rigidbody.freezeRotation = true;
}
 
void  LateUpdate (){
    if (target  camera) {
 
   //Zooming with mouse
   distance += Input.GetAxis("Mouse ScrollWheel")*distance;
   distance = Mathf.Clamp(distance, minDistance, maxDistance);
 
   //Detect mouse drag;
   if(Input.GetMouseButton(0))   {
   
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;       
      }
      y = ClampAngle(y, yMinLimit, yMaxLimit);
              
        Quaternion rotation= Quaternion.Euler(y, x, 0);
		Vector3 vTemp = new Vector3(0.0f, 0.0f, -distance);
        Vector3 position= rotation * vTemp + target.position;
         
   transform.position = Vector3.Lerp (transform.position, position, cameraSpeed*Time.deltaTime);
      transform.rotation = rotation;      
    }
}
 
static float  ClampAngle ( float angle ,   float min ,   float max  ){
   if (angle < -360)
      angle += 360;
   if (angle > 360)
      angle -= 360;
   return Mathf.Clamp (angle, min, max);
}

}

hmmm… not much modification for a touch screen.

First, touches are not based the same way that mice are. What you are looking for is the deltaPosition. This tells you about what GetAxis do. As far as zooming, you would have to keep track of two fingers and thier id’s and use the distance between the deltaPosition’s to zoom in or out. Kind of tricky.

Thanks BigMisterB… I’m very new to scripting in Unity or scripting at all for that matter. Can you provide an example script of what you’re suggesting?