Unity Android触摸输入重置



首先,我对我的英语成绩感到抱歉
我希望玩家在输入一次触摸时移动,并且只在输入两次触摸时使用技能
下面的代码似乎很好,只是当我输入两次触摸,然后取消">第一次触摸">并重新输入触摸时,它出错了
但如果我取消strong文本第二次触摸,效果会很好

public class Test : MonoBehaviour {
private void Update() {
if(Input.touchCount > 0) {Movement();}
if(Input.touchCount > 1) {Skill();}
}
private void Movement() {
Vector2 inputPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
transform.position = Vector3.MoveTowards(transform.position, inputPos, 30f * Time.deltaTime);
}
private void Skill() {print("skill fired");}
Working as Intended
//  [1]: https://imgur.com/ngjoabY
//  [2]: https://imgur.com/kkDAGEW

Problem the second reinput should fire skill instead of moving toward that
//  [3]: https://imgur.com/gD0x8rP
//  [4]: https://imgur.com/o06mJgs
}

在你给它两次触摸,并去掉第一次触摸后,第二次触摸变成第一次触摸,它被捕获在if(Input.touchCount>0({Movement((;}中
所以在这个阶段,如果你再次输入,应该是GetTouch(1(,对吗
但重新输入的第二次触摸变为GetTouch(0(
因此,本应使用技能的对象移动到第二个输入位置我已经尽了我所能,但我找不到解决办法
我在想,如果我能为Input Touches刷新缓冲区,我就能做到,但它只有Get方法
And Input.simulateMouseWithTouches它不起作用
触摸类变量甚至不能与null进行比较

是否需要获取触摸次数
您可以使用跨平台输入。导入CrossPlatForm资源->导入->CrossPlatFormInput。

导入后转到标准资产->CrossPlatformInput->预制件->5个不同的预制件,选择更适合您项目的。

最新更新