zoukankan      html  css  js  c++  java
  • 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);
          }
        }
      }

    }

  • 相关阅读:
    U3D shaderlab 相关指令开关
    CCF NOI1073
    CCF NOI1185
    CCF NOI1077(自然数的拆分问题 )
    CCF NOI1070(汉诺塔)
    CCF NOI1069
    2018年全国多校算法寒假训练营练习比赛(第一场)G.圆圈
    poj1941(递归)
    Codeforce914B (Conan and Agasa play a Card Game)
    Codeforce916B
  • 原文地址:https://www.cnblogs.com/Study088/p/7272240.html
Copyright © 2011-2022 走看看