Unity3D:增加Multi-Tap输入
本文关键字:输入 Multi-Tap 增加 Unity3D | 更新日期: 2023-09-27 18:11:10
如何在Unity3D游戏中添加多点点击(而非多点触摸!)输入?我很难找到关于这方面的有用信息。
我目前得到的是多点触控输入支持。这就是我使用的:
private Vector2 _touchOrigin = -Vector2.one;
public bool TouchEnded(int touchCount = 1)
{
if (Input.touchCount != touchCount) return false;
Touch lastTouch = Input.GetTouch(touchCount - 1);
if (lastTouch.phase == TouchPhase.Began)
{
_touchOrigin = lastTouch.position;
}
else if (lastTouch.phase == TouchPhase.Ended && _touchOrigin.x >= 0)
{
_touchOrigin.x = -1;
return true;
}
return false;
}
我想做的是写一个类似的方法,但多点点击。例如,用户必须同时点击几个手指(touchCount)多次(tapCount)。这将是方法签名:
public bool TapEnded(int touchCount = 1, int tapCount = 2)
{
}
谁能给我一些帮助如何使这个要求工作?
您可以使用Input。返回代表上一帧中所有触摸状态的对象列表。链接http://docs.unity3d.com/ScriptReference/Input-touches.html
void Update() {
int fingerCount = 0;
foreach (Touch touch in Input.touches) {
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
fingerCount++;
}
if (fingerCount > 0)
print("User has " + fingerCount + " finger(s) touching the screen");
}