turn camera with touch unity code example
Example: turn camera with touch unity
Vector3 FirstPoint;
Vector3 SecondPoint;
float xAngle;
float yAngle;
float xAngleTemp;
float yAngleTemp;
void Start () {
xAngle = 0;
yAngle = 0;
this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0);
}
void Update () {
if(Input.touchCount > 0){
if(Input.GetTouch(0).phase == TouchPhase.Began){
FirstPoint = Input.GetTouch(0).position;
xAngleTemp = xAngle;
yAngleTemp = yAngle;
}
if(Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved){
SecondPoint = Input.GetTouch(0).position;
xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
yAngle = yAngleTemp + (SecondPoint.y - FirstPoint.y) * 90 / Screen.height;
this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
}
}
}