【发布时间】:2020-01-20 18:38:13
【问题描述】:
我想用统一的方式旋转一个对象。只要用户按住触摸,我的触摸向左移动,对象就应该向左旋转,反之亦然。 只要触摸向左或向右移动,我的代码就会正确旋转对象。稍后,如果停止并按住触摸移动,则对象开始向右旋转。这是我尝试过的。
{
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
oldTouchPosition = touch.position;
}
else if (touch.phase == TouchPhase.Moved)
{
if (touch.deltaPosition.x > 10f)
{
rotateLeftward = false;
rotateRightward = true;
}
else if (touch.deltaPosition.x < 10f)
{
rotateRightward = false;
rotateLeftward = true;
}
}
if(rotateLeftward == true )
{
RotateLeftWard();
}
else if (rotateRightward == true)
{
RotateRightWard();
}
}
}
void RotateLeftWard()
{
transform.rotation = Quaternion.Euler(0f, 1 * keepRotateSpeed, 0f) * transform.rotation;
}
void RotateRightWard()
{
transform.rotation = Quaternion.Euler(0f, -1 * keepRotateSpeed, 0f) * transform.rotation;
}
【问题讨论】:
-
您应该直接使用移动的 deltaPosition 进行旋转或使用
Transform.Rotate和Time.deltaTime.. 目前您只需将每一帧旋转大约一个固定的量,但前提是您爱得足够快.. ..