以下为视角的旋转实现方式(仅供参考)
using UnityEngine;
public class camera_controller : MonoBehaviour
{
public GameObject _camera;
private Vector3 rot = new Vector3(0, 0, 0);
//鼠标速度
private int mousespeed = 100;
private void FixedUpdate()
{
//运行环境为Windows
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
rot.y += Input.GetAxis("Mouse X") * mousespeed * Time.deltaTime;
rot.x = rot.x - Input.GetAxis("Mouse Y") * mousespeed * Time.deltaTime;
if (rot.x >= 90)
{
rot.x = 90;
}
if (rot.x <= -90)
{
rot.x = -90;
}
_camera.transform.localEulerAngles = rot;
}
//运行环境为安卓
else if (Application.platform == RuntimePlatform.Android)
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
rot.x -= Input.GetTouch(0).deltaPosition.y * 0.1f;
if (rot.x >= 90)
{
rot.x = 90;
}
if (rot.x <= -90)
{
rot.x = 90;
}
rot.y += Input.GetTouch(0).deltaPosition.x * 0.1f;
_camera.transform.localEulerAngles = rot;
}
}
}
}