0
\$\begingroup\$

How do I detect a pinch motion on Unity for an android or Iphone? I need to also know whether the player pinches a certain character or not. How do i do that?

\$\endgroup\$
1
2
\$\begingroup\$

in videogames most of the time you have to look for some math models for events or interactions you see.

pinch: only 2 active touch on the screen with distance more than a threshold if their distance is less than a threshold in any amount of time, a pinch has happened.

there are lots of plugins for gesture detection in asset store. just look them or implement it on your own of you like the problem. this a sample code for touch states on screen.

void Update ()
{
    int activeTouches = Input.touchCount;

    if (activeTouches > 0) {
        print (activeTouches + " touch(es) detected");

        for (int i = 0; i < activeTouches; i++) {
            Touch touch = Input.GetTouch (i);

            print ("Touch index " + touch.fingerId + " detected at position " + touch.position);

            switch (touch.phase) {
            case TouchPhase.Began:
                print ("User did touch the screen");
                break;
            case TouchPhase.Moved:
                print ("User dragging or moving his finger");
                break;
            case TouchPhase.Ended:
                print ("User did lift up his finger");
                break;
            }
        }
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ thanks for the help, I looked on the asset store, and I'll probably use the "lean touch" free package. \$\endgroup\$
    – Millard
    Aug 20 '19 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .