[Unity]Object跟随鼠标移动而旋转

   
    private float minXRotation = -40;
    private float maxXRotation = 40;
    private float minYRotation = -60;
    private float maxYRotation = 60;

    private void Update()
    {
        float xPosPrecent = Input.mousePosition.x / Screen.width;
        float yPosPrecent = Input.mousePosition.y / Screen.height;

        float xAngle = -Mathf.Clamp(yPosPrecent * maxXRotation, minXRotation, maxXRotation);
        float yAngle = Mathf.Clamp(xPosPrecent * maxYRotation, minYRotation, maxYRotation);
        this.gameObject.transform.eulerAngles=new Vector3(xAngle, yAngle, 0);
    }

///Mathf.Clamp(value,min,max);

    //当旋转角度大于max,value=max;

    //当旋转角度小于min,value=min;

    //else value=value;


TonyChen

2018.4.1

猜你喜欢

转载自blog.csdn.net/u013284706/article/details/79778811