1
NGUI 3 Support / (solved) NGUI & long touch & gas pedal
« on: July 29, 2014, 02:36:40 PM »
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..
------------------------------------------------------------------------
I've solved and here is solution :
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;
- 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);
- }
- }
- }
