Unity:捏合旋转GameObject而不是相机

时间:2017-11-18 12:36:17

标签: c# unity3d

        if (Input.touchSupported && Input.touchCount == 2) {

            // Store both touches.
            Touch touchZero = Input.GetTouch (0);
            Touch touchOne = Input.GetTouch (1);

            // Find the position in the previous frame of each touch.
            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

            // Find the difference in the distances between each frame.

            Vector2 previousDirection = touchOnePrevPos - touchZeroPrevPos;
            Vector2 currentDirection = touchOne.position - touchZero.position;

            int sign = Vector3.Cross(touchZero.position, touchZeroPrevPos).z < 0 ? 1 : -1;


            if(touchOne.position.y > touchZero.position.y)
                {
                    sign = - sign;
                }


            float angle = Vector2.Angle(previousDirection, currentDirection) * sign ;
            Vector3 rotateAround = (transform.position - Camera.main.transform.position).normalized;
            transform.Rotate(rotateAround, angle, Space.World);

这是我当前的代码,但它非常挑剔,并且无法一直正常工作,如果我旋转设备,它会崩溃。

0 个答案:

没有答案