I found this online and it works but the camera doesn’t follow smoothly.
here is the code:
//The standard mouse orbt script converted to work with touch devices (android and iOS) by Newtonians. Feel free to use or modify
//Check out the blog http://newtonians3d.blogspot.com/
using UnityEngine;
using System.Collections;
public class touchorbit : MonoBehaviour {
private float x;
private float y;
public float xspeed;
public float yspeed;
private Touch touch;
public float distance = 10;
public Transform target;
Rect margin;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
margin = new Rect(Screen.width * 0.5f, 0, Screen.width, Screen.height * 1.0f);
float count = Input.touchCount;
for (int i = 0; i < count; i++)
{
Touch tc = Input.GetTouch(i);
if(margin.Contains(tc.position)){
x += tc.deltaPosition.x * xspeed * 0.02f;
y -= tc.deltaPosition.y * yspeed * 0.02f;
}
}
Quaternion rotation = Quaternion.Euler (y, x, 0);
Vector3 position = rotation * (new Vector3(0.0f, 0.0f, -distance)) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
If you need it here is a video of the problem: