【发布时间】:2018-07-13 01:43:05
【问题描述】:
使用 Unity3D 2018.2
正在尝试单击、双击和按住。
存在的问题:
单击:有时不会注册我的单击
双击:每次双击设备时都会调用 8 次
Triple Tap:双击被调用 10 次,Triple 被调用 9 次
这是我的代码,如果是 C# 和 Unity 的新手,我无法正确完成这样一个简单的任务,我们将不胜感激
private void handleTouchTypes()
{
foreach (Touch touch in Input.touches)
{
float tapBeginTime = 0;
float tapEndedTime = 0;
// Touches Began
if (touch.phase == TouchPhase.Began)
{
tapBeginTime = Time.time;
}
// Touches Ended
if (touch.phase == TouchPhase.Ended)
{
tapEndedTime = Time.time;
// Single Touch: for 0.022f of a Second
if (touch.tapCount == 1 && ((tapEndedTime - tapBeginTime) < 0.03f))
{
Debug.Log("Single Touch");
}
// Hold Touch: within half a second .5f to 1f
if (touch.phase == TouchPhase.Moved && touch.deltaPosition.magnitude < 0.02f && (tapEndedTime - tapBeginTime) >= 0.5f && (tapEndedTime - tapBeginTime) <= 1f)
{
Debug.Log("Holding Touch");
}
}
if (touch.tapCount == 2)
{
// Double Tap
Debug.Log("Double Tap");
}
if (touch.tapCount >= 3)
{
// Triple Tap
Debug.Log("3 Touches and/or more");
}
}
}
【问题讨论】:
标签: c# android ios unity3d touch