private float m_timer;
private float cTime;
private float CanLastTimer = 0.15f;
/// <summary>
/// 检测长按
/// </summary>
private async void AsyncMouseDown()
{
m_timer = 0;
cTime = Time.deltaTime;
//Debug.Log("EventTrigger-->初始坐标" + oldPosition + " " + cTime);
while (m_timer < 2)
{
if (this.gameObject == null) return;
try
{
if (Input.GetMouseButton(0))
{
m_timer += 0.005f;
await Task.Delay(5);
}
else
{
Debug.Log(m_timer);
if (m_timer < CanLastTimer)
{
//点击了
CameraMove();
}
else
{
//长按了
}
return;
}
}
catch (Exception e) { Debug.LogError(e.Message); return; }
}
}
}
unity 按钮监听长按
于 2021-06-07 14:56:31 首次发布