2016-11-22 47 views
-1

我基本上是編程方面的新手,我遇到了閏秒運動傳感器問題,無法檢測到雙擊。有人能幫助我嗎?如何在閏距運動傳感器中製作雙擊手勢

所以這是我爲我的菜單代碼:

using UnityEngine; 
using System.Collections; 

public class Touch : MonoBehaviour { 

void OnCollisionEnter(Collision other){ 
    Debug.Log ("Collision Event " + other.transform.name); 
    string tipOfHand = other.transform.parent.name; 
    if (tipOfHand == "index") { 
     Application.LoadLevel(1); 
    } 
    } 
} 
+2

你知道如何檢測一個水龍頭嗎?你知道如何計算兩次函數調用之間的時間嗎?然後,你知道如何檢測雙擊;) – Hellium

+0

此外,不要忘記檢查Leap Motion論壇:https://community.leapmotion.com/t/implementing-double-tap-gesture/710 – Hellium

+0

@Hellium先生,我編輯我的問題,你可以幫我 –

回答

0

試試下面的代碼。我沒有測試它:

using UnityEngine; 
using System.Collections; 

public class Touch : MonoBehaviour 
{ 
    public float doubleTapMaxDelay = 0.5f ; 
    private float firstTapTime ; 

    void OnCollisionEnter(Collision other) 
    { 
     Debug.Log ("Collision Event " + other.transform.name); 
     string tipOfHand = other.transform.parent.name; 
     if (tipOfHand == "index") 
     { 
      // Detect if second tap occured within the given max delay 
      if((Time.time - firstTapTime) < doubleTapMaxDelay) 
      { 
       // Double tap 
       firstTapTime = 0 ; 
       Application.LoadLevel(1); 
      } 
      // Else, indicate the time the first tap has been made 
      else 
      { 
       // Single tap 
       firstTapTime = Time.time ; 
      } 
     } 
     } 
    } 
}