基本上我想要做的是创建一些代码,当触摸在屏幕上滑动时会注册,所以我可以通过触摸控件移动我的角色。用于检测滑动方向的逻辑
我写的东西有时似乎有效,当它发生时,会使角色多次移动。
这里是我的代码:
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