//放大、缩小
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
gameObject.transform.Translate(new Vector3(0, 0, Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * view_value));
}
//移动视角
if (Input.GetMouseButton(2))
{
this.gameObject.transform.Translate(Vector3.left * Input.GetAxis("Mouse X") * move_speed);
this.gameObject.transform.Translate(Vector3.up * Input.GetAxis("Mouse Y") * -move_speed);
}
//旋转视角
if (Input.GetMouseButton(1))
{
this.transform.RotateAround(center.transform.position, Vector3.up, (Input.GetAxis("Mouse X") * 5));
this.transform.RotateAround(center.transform.position, transform.right, Input.GetAxis("Mouse Y") * 5);
}
center为默认的中心点GameObject,将当前脚本写入Update(),拖到Camera上即可完成:相机视角的拉远缩进、移动视角、相机围绕某个中心点旋转