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

三维物体跟随鼠标移动

时间:2018-09-26 19:09:12      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:span   recent   screen   鼠标移动   void   sep   date()   mat   lam   

 //上下 x(-45,15) 
    //左右 y(-60,60) 
    private float maxYRotation = 120;
    private float minYRotation = 0;
    private float maxXRotation = 60;
    private float minXRotation = 0;
 void Update()
    {
       //计算出鼠标在屏幕上的位置
            float xPosPrecent = Input.mousePosition.x / Screen.width;
            float yPosPrecent = Input.mousePosition.y / Screen.height;

            //Mathf.Clamp 限制value的值在min和max之间 如果value小于min,返回min。如果value大于max,返回max,否则返回value 
            float xAngele = -Mathf.Clamp(yPosPrecent * maxXRotation, minXRotation, maxXRotation) + 15;
            float yAngele = Mathf.Clamp(xPosPrecent * maxYRotation, minYRotation, maxYRotation) - 60;

            transform.eulerAngles = new Vector3(xAngele, yAngele, 0);
        }
      
    }

 

三维物体跟随鼠标移动

标签:span   recent   screen   鼠标移动   void   sep   date()   mat   lam   

原文地址:https://www.cnblogs.com/y1016/p/9708720.html

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