基本上我想要做的是創建一些代碼,當觸摸在屏幕上滑動時會註冊,所以我可以通過觸摸控件移動我的角色。用於檢測滑動方向的邏輯
我寫的東西有時似乎有效,當它發生時,會使角色多次移動。
這裏是我的代碼:
if (Input.touches [0].phase == TouchPhase.Ended) {
Debug.Log (Input.touches [0].deltaPosition);
if (Input.touches[0].deltaPosition.y > Input.touches[0].deltaPosition.x || Input.touches[0].deltaPosition.y > (-Input.touches[0].deltaPosition.x))
movePlayer ("Up");
if ((-Input.touches[0].deltaPosition.y) > Input.touches[0].deltaPosition.x || (-Input.touches[0].deltaPosition.y) > (-Input.touches[0].deltaPosition.x))
movePlayer ("Down");
if ((-Input.touches[0].deltaPosition.x) > Input.touches[0].deltaPosition.y || (-Input.touches[0].deltaPosition.x) > (-Input.touches[0].deltaPosition.y))
movePlayer ("Left");
if (Input.touches[0].deltaPosition.x > Input.touches[0].deltaPosition.y || Input.touches[0].deltaPosition.x > (-Input.touches[0].deltaPosition.y))
movePlayer ("Right");
}
任何意見將是很有益的
up case ...'y> x && y> -x'?換句話說,你在這裏測試什麼? – spender 2015-01-26 20:14:03
好吧,這是從我搞亂,因爲我變得惱火,但改變它||而不是&&似乎並沒有做任何事情 – Zoomz09 2015-01-26 20:17:54