The way to check long press on touch screen

I found that there is no inherent method to get the long press on touch screen in unity engine. However, it is easy to get it, there are two simple ways I found.

Check it on update by after script

bool CheckForLongPress() {
    if (Input.touches[0].phase == TouchPhase.Began) { // If the user puts her finger on screen...
        _timePressed = Time.time - _timeLastPress;
    }

    if (Input.touches[0].phase == TouchPhase.Ended) { // If the user raises her finger from screen
        _timeLastPress = Time.time;
        if (_timePressed > WaitingSeconds/2f) { // Is the time pressed greater than our time delay threshold?
            return true;
        }
    }
    return false;
}

And get it from my gists on github

Use LeanTouch

LeanTouch is a free input plugin for unity3d, it got 5 stars’ rating by 92 votes.

lt

There is one simple event to deal with the long press – Lean.LeanTouch.OnFingerHeldDown

void OnEnable()
    {
        Lean.LeanTouch.OnFingerHeldDown += OnFingerHeldDown;
    }

    void OnDisable()
    {
        Lean.LeanTouch.OnFingerHeldDown -= OnFingerHeldDown;
    }


    void Start () {
        Lean.LeanTouch.Instance.HeldThreshold=.5f
    }

    public void OnFingerHeldDown(Lean.LeanFinger finger){
        Debug.log("long press ");
    }

You can get it from asset store.