首页 > 移动平台 > 详细

三维物体跟随鼠标移动

时间:2018-09-26 18:41:04      阅读:329      评论:0      收藏:0      [点我收藏+]
 //上下 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);
        }
      
    }

 

三维物体跟随鼠标移动

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!