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);
      }
    }
  }

}

unity实现用鼠标右键控制摄像机视角上下左右移动的更多相关文章

  1. unity中鼠标左键控制摄像机视角上下左右移动

    enum RotationAxes { MouseXAndY, MouseX, MouseY } RotationAxes axes = RotationAxes.MouseXAndY; //@Hid ...

  2. 【Unity3D】使用鼠标键盘控制Camera视角(即时战略类游戏视角):缩近,拉远,旋转

    今天写一个demo,要用到鼠标键盘控制三维视角,因此写了个脚本用于控制. 该脚本可以用于即时战略类游戏的视角,提供了缩进,拉伸,旋转.同时按住鼠标右键不放,移动鼠标可以实现第一人称视角的效果. usi ...

  3. unity鼠标滚轮控制摄像机视野的缩放和按住鼠标控制摄像机移动

    //摄像机前进后退的速率 private float view_value=20f; private float maximum = 100; private float minmum = 30; / ...

  4. unity windowEditor平台下鼠标左键控制摄像机的视角

    工作的原因,今天就只写了unity下的鼠标左键控制摄像机的视角左右上下调节:明天,补齐.[有诸多参考,着实是需要多多加油的] using System.Collections; using Syste ...

  5. [Unity菜鸟] 摄像机视角控制

    1. 摄像机预览物体 上下左右远近 把CameraFollow脚本赋给Camera,把要观察的对象赋给target using UnityEngine; using System.Collection ...

  6. Directx11教程(58) 鼠标控制摄像机

    原文:Directx11教程(58) 鼠标控制摄像机        本篇教程我们实现鼠标旋转摄像机的操作.主要就是按下鼠标左键的时候,根据鼠标的移动对摄像机进行pitch, raw的组合旋转.具体修改 ...

  7. Unity相机鼠标基本控制

    一.滚轮控制视角缩放 /// <summary> /// 滚轮控制相机视角缩放 /// </summary> public void CameraFOV() { //获取鼠标滚 ...

  8. Unity 添加鼠标右键事件

    把此类放到 Editor下使用就OK using UnityEngine; using System.Collections; using System.Collections.Generic; us ...

  9. U3D学习09-物体简单控制及视角观察

    一.Character Control非刚体 1.场景初始化,注意调整CC的轴心,不需要碰撞,且删除CC子物体的碰撞.2.移动:       获取X,Z轴变化,定义变量h,v:        定义移动 ...

随机推荐

  1. 关于vue2.0获取后端数据

    一.通过vue-rource完成异步请求: 其用法跟ajax用法差不多,也就是改变了一些语法格式.从获取路径到值的获取都是一样的,但是有一点是不同的就是ajax获取到的数据会自动转成json格式,而v ...

  2. js,java时间处理

    1.JS获取时间格式为“yyyy-MM-dd HH:mm:ss”的字符串 function getTimeStr(){ var myDate = new Date(); var year = myDa ...

  3. https 学习笔记

    参考 : http://www.cnblogs.com/JimmyZhang/archive/2008/10/02/Cryptograph.html https://blog.csdn.net/Jog ...

  4. 下一个更大的数 Next Greater Element

    2018-09-24 21:52:38 一.Next Greater Element I 问题描述: 问题求解: 本题只需要将nums2中元素的下一个更大的数通过map保存下来,然后再遍历一遍nums ...

  5. (8)进程---Queue队列

    # IPC Inter-Process Communication # 实现进程之间通信的两种机制: # 管道 Pipe 用的很少 # 队列 Queue 队列的特征:现进先出,栈属于后进后出 基本语法 ...

  6. SpringData Redis

    Redis spring-data-redis

  7. 开发者说 | Apollo控制算法之汽车动力学模型和LQR控制

    参考:https://mp.weixin.qq.com/s?__biz=MzI1NjkxOTMyNQ==&mid=2247486444&idx=1&sn=6538bf1fa74 ...

  8. 11月28日 记录一个错误❌,看ruby on rails --active support core extensions--present? && presence && duplicable?

    ❌错误 1. @job.resume.count: 提示❌   undefined method `resume' ✅: @job.resumes.count  //解释:调出某一个job的所有简历, ...

  9. 2019/01/17 对django项目部署的学习

    前记:最近在学习django项目的部署. 开发环境:windows10,使用pycharm,python2.7.15,django1.11.本地测试使用nginx和前端交互. 生产环境:centos7 ...

  10. find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax

    1.3.100 find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax find_first_zero_bit 修订后: /* * Find-bit routines ...