码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-11-24 23:58:26      阅读:530      评论:0      收藏:0      [点我收藏+]

标签:inpu   axis   color   locale   frame   ==   vector   nim   tor   

enum RotationAxes { MouseXAndY, MouseX, MouseY }
RotationAxes axes = RotationAxes.MouseXAndY;
//@HideInInspector
float sensitivityX = 15;
//@HideInInspector
float sensitivityY = 15;
//private float minimumX = -360; 原文有此行但并未使用此变量
//private float maximumX = 360; 同上
float minimumY = -80;
float maximumY = 80;
private float rotationY = 0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
    if (Input.GetMouseButton(0))
    {
        if (axes == RotationAxes.MouseXAndY)
        {
            float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
            rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
            rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
            transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
        }
        else if (axes == RotationAxes.MouseX)
        {
            transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        }
        else
        {
            rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
            rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
            transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
        }
    }
}

 

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

标签:inpu   axis   color   locale   frame   ==   vector   nim   tor   

原文地址:http://www.cnblogs.com/Study088/p/7892528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!