Hey,
I’m trying to write a method that detects when a key is tapped twice within a certain range of time. Here’s the non-functional code I have:
public bool isLookingRight;
public bool isLookingLeft;
public bool hasDoubleTapped;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public bool MultiTapKey (string keyName, int numberOfTaps, float rangeOfSeconds) {
if (cInput.GetKeyDown(keyName))
{
if ( rangeOfSeconds > 0 && numberOfTaps == 1)
{
hasDoubleTapped = true;
}
else
{
numberOfTaps += 1 ;
}
}
if ( rangeOfSeconds > 0 )
{
rangeOfSeconds -= 1 * Time.deltaTime ;
}
else
{
numberOfTaps = 0 ;
}
if (cInput.GetKeyUp(keyName))
{
hasDoubleTapped = false;
}
return hasDoubleTapped;
}
}
Can anyone help me out with a way to do this?