I was using GUITexture for gas/brake pedals for an android game but I decided to use NGUI. And it's going a little messy.
Anyway here is problem: How can I catch the long press? Below method is not working..
private float _longClickDuration = 2f;
float _lastPress = -1f;
void OnPress(bool pressed)
{
if (pressed)
_lastPress = Time.realtimeSinceStartup;
else
{
if (Time.realtimeSinceStartup - _lastPress > _longClickDuration)
DoLongPress();
}
}
------------------------------------------------------------------------
I've solved and here is solution :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LongTouch : MonoBehaviour
{
bool mIsPressed = false;
public float interval = 0.0001525F;
float mNextClick = 0f;
public List
<EventDelegate
> onPressListeners
= new List
<EventDelegate
>(); public List
<EventDelegate
> onNotPressListeners
= new List
<EventDelegate
>();
void OnPress (bool isPressed) { mIsPressed = isPressed; mNextClick = Time.realtimeSinceStartup + interval; }
void Update ()
{
if (mIsPressed && Time.realtimeSinceStartup > mNextClick) {
mNextClick = Time.realtimeSinceStartup + interval;
EventDelegate.Execute (onPressListeners);
} else {
EventDelegate.Execute (onNotPressListeners);
}
}
}