K
K
Konstantin Dovnar2017-02-11 15:12:38
Unity
Konstantin Dovnar, 2017-02-11 15:12:38

Unity: tap in place?

Such a thing - it is necessary to determine the tapas on the screen, and those that occurred in one place.
That is, a person tapped on the screen without moving his finger anywhere.
There is a tapCount, but it works for any events with a touch, that is, it disappears.
So far, I made a crutch for myself in the form of something like this:

private Vector2 m_StartTouch;

void Update () {
    if(Input.touchCount > 0) {
        Touch touch = Input.GetTouch(0);
        if(touch.phase == TouchPhase.Began) {
            m_StartTouch = touch.position;
        } else if(touch.phase == TouchPhase.Ended) {
            Vector2 endPosition = touch.position - m_StartTouch;
            if(endPosition.magnitude <= 0) {

            }
        }
    }
 }

That is, I just look at the length of the wheelbarrow, if it is more than 0, it means they drove around the screen.
However, I hope there is a better way to do this, because a similar definition is used in several scripts with different conditions.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question