unity实现用鼠标右键控制摄像机视角上下左右移动

using System;
using System.Collections.Generic;
using UnityEngine;
public class ViewControl
{
  enum RotationAxes
  {
    MouseXAndY,
    MouseX,
    MouseY
  }
  RotationAxes axes = RotationAxes.MouseXAndY;

  float sensitivityX = 10;
  float sensitivityY = 10;

  float minimumY = -45;
  float maximumY = 45;
  private float rotationY = 0;

  public void Update()
  {
    if (Input.GetMouseButton(0))
    {
      if (axes == RotationAxes.MouseXAndY)
      {
        float rotationX = Camera.main.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
        Camera.main.transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
      }
      else if (axes == RotationAxes.MouseX)
      {
        Camera.main.transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
      }
      else
      {
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
        Camera.main.transform.localEulerAngles = new Vector3(-rotationY, Camera.main.transform.localEulerAngles.y, 0);
      }
    }
  }

}

上一篇:让策划也能轻松修改数据的方法:运用Excel2Json2Object插件将xml表格转为Object导入脚本


下一篇:Postman+newman+jenkins构建