在编程方面,我基本上是新手,我的飞跃运动传感器出现问题,我无法检测到双击。有人可以帮帮我吗?
所以这是我的菜单代码:
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);
}
}
}
答案 0 :(得分: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 ;
}
}
}
}
}