我设置了一个脚本,以便在触摸/拖动移动屏幕的右侧时,相机应该移动。除了相机抖动(所有代码都在LateUpdate()中)之外,这完全可以正常工作。是否有更好的方法可以使此过程更流畅?为了完整起见,这是第三人称相机。
for (int i = 0; i < Input.touchCount; i++)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Vector3 p = Input.GetTouch(i).position;
Debug.Log(p);
if (p.x < Screen.width / 3 * 1)
{
//touched on the left
//do other code
Debug.Log("Touch Left");
}
else
{
//touched on the right
//do other code
Debug.Log("Right Touch");
firstpoint = Input.GetTouch(i).position;
xAngTemp = xAngle;
yAngTemp = yAngle;
}
}
if (Input.GetTouch(i).phase == TouchPhase.Moved)
{
Vector3 p = Input.GetTouch(i).position;
Debug.Log(p);
if (p.x < Screen.width / 3 * 1)
{
//touched on the left
//do other code
Debug.Log("Move Left");
}
else
{
//touched on the right
//do other code
Debug.Log("Move Right");
secondpoint = Input.GetTouch(i).position;
//Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 180.0f / Screen.width;
yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 90.0f / Screen.height;
yAngle = Mathf.Clamp(yAngle, -50, 50);
//Rotate camera
transform.LookAt(Target);
Target.rotation = Quaternion.Euler(yAngle, xAngle, 0);
Player.rotation = Quaternion.Euler(0, xAngle, 0);
}
}
}