zoukankan      html  css  js  c++  java
  • u3d按住鼠标右键才转动摄像机的方法

    unity3d获取鼠标3个键的响应如下:
    鼠标左键GetMouseButton(0)
    鼠标右键GetMouseButton(1)
    鼠标中键GetMouseButton(2)

    知道了鼠标的响应要做到按下右键再转动摄像机就简单了。
    建好一工程UNITY自带的脚本MouseLook.cs中已经把通过鼠标移动旋转摄像机的功能做好了。想要按下右键才再转动摄像机。只要在Update()的相应位置加上Input.GetMouseButton(1)就可以了。
    代码如下:

    void Update ()
     {
      if(Input.GetMouseButton(1))
      {
       if (axes == RotationAxes.MouseXAndY)
       {
        // Read the mouse input axis
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationX = ClampAngle (rotationX, minimumX, maximumX);
        rotationY = ClampAngle (rotationY, minimumY, maximumY);
        
        Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
        Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
        
        transform.localRotation = originalRotation * xQuaternion * yQuaternion;
       }
       else if (axes == RotationAxes.MouseX)
       {
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationX = ClampAngle (rotationX, minimumX, maximumX);
        Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
        transform.localRotation = originalRotation * xQuaternion;
       }
       else
       {
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = ClampAngle (rotationY, minimumY, maximumY);
        Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
        transform.localRotation = originalRotation * yQuaternion;
       }
      }
     }
  • 相关阅读:
    [杭电_HDU] 2013
    动态调整线程数的python爬虫代码分享
    wampserver 配置的几个坑(雾
    wampserver apache 403无权限访问 You don't have permission to access /index.html on this server
    [爬坑日记] 安卓模拟器1903蓝屏 没开hyper-v
    [单片机] ESP8266 开机自动透传
    [操作系统] 死锁预防和死锁避免
    [linux] 手机Deploy linux 桌面中文乱码
    XHTML基础
    JDBC_c3p0连接池
  • 原文地址:https://www.cnblogs.com/fm168/p/3045760.html
Copyright © 2011-2022 走看看