1 回答

TA貢獻1818條經驗 獲得超3個贊
由于我是新來的,我還不能使用評論來提出更多問題。使用三星時到底什么不起作用?
不過,您可以簡化計算。
float swipeValue = touch.position.x - startPos.x; //Mathf.Sign(touch.position.x - startPos.x);
if (swipeValue > 0)
{//right swipe
anim.Play(change_Line_Animation);
transform.localPosition = second_PosOfPlayer;
SoundManager.instance.PlayMoveLineSound();
}
else if (swipeValue < 0)
{//left swipe
anim.Play(change_Line_Animation);
transform.localPosition = first_PosOfPlayer;
SoundManager.instance.PlayMoveLineSound();
}
僅比較 > 或 < 小于 0 時不需要 Math.Sign。
case TouchPhase.Began:
startPos = touch.position.x; // startPos could be float
break;
因此,
float swipeDistHorizontal = Mathf.Abs(touch.position.x - startPos);
如果游戲僅使用水平滑動,則不需要向量來存儲和計算滑動增量。
如果您提供更多信息,我很樂意提供更多幫助。
- 1 回答
- 0 關注
- 400 瀏覽
添加回答
舉報