0

首先,我会让你知道我是 Unity 和整体编码的新手(我知道一些非常基本的 javascript 编码)。我的问题:每次触摸屏幕时,如何在某个轴(在我的情况下是 z 轴,所以它像你看着方向盘一样旋转)上旋转 2D 对象(预制件)120 度。现在我有这样的:

function TouchOnScreen ()
{
    if (Input.touchCount > 0)
    {
        var touch = Input.touches[0];
        if (touch.position.x < Screen.width/2)
        {
            transform.rotation = Quaternion.Euler(0,0,120);
            Debug.Log("RotateRight");
        }
        else if (touch.position.x > Screen.width/2)
        {
            transform.rotation = Quaternion.Euler(0,0,-120);
            Debug.Log("RotateLeft");
        }
    }
}

每当我按下屏幕的某一侧时,此代码都会旋转对象,但不是我想要的方式。我希望它旋转,以便您看到对象从 A 旋转到 B,但不是(像现在这样)在一帧中从 A 到 B。此外,此代码仅允许我向每个方向旋转一次。

我怎样才能让它每当我按下屏幕的某一侧时,它会增加或减少之前旋转的角度,这样我就可以继续旋转。

注意:请使用 javascript,如果您知道更简单的代码,请告诉我!

非常感谢您的帮助,在此先感谢!

4

1 回答 1

3

代替

        transform.rotation = Quaternion.Euler(0,0,-120);

你用:

        var lSpeed = 10.0f; // Set this to a value you like
        transform.rotation = Quaterion.Lerp ( transform.rotation, Quaternion.Euler(0,0,-120), Time.deltaTime*lSpeed);
于 2014-09-09T16:11:24.340 回答