Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Double Tap on iOS different to Android behaviour?

Discussion in 'iOS and tvOS' started by DannyDan, Mar 18, 2012.

  1. DannyDan

    DannyDan

    Joined:
    Mar 22, 2010
    Posts:
    27
    Hi,

    today I came up to an issue were I'm not able to get a solution for.
    I want to zoom in with a doubletap. Its working just fine on my Android Device, but when I try the exact same code on an iPad, its not working and I dont know why?

    I already searched this Forum and the Unify Forum for any clue but with no luck.

    Any1 got a similar behaviour and eventually solved this problem?

    Here is my code snippet:

    Code (csharp):
    1. float lastTapTime = -1;
    2. float tapTime = -1;
    3. float doubleTapThreshold = 0.5f;
    4. bool doubleTap = false;
    5.  
    6. void FixedUpdate()
    7. {
    8.    if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Began  Input.GetTouch(0).phase != TouchPhase.Moved)
    9.    {
    10.        lastTapTime = tapTime;
    11.        tapTime = Time.time;
    12.                
    13.        if (tapTime - lastTapTime <= doubleTapThreshold)
    14.           doubleTap = true;
    15.        else
    16.           doubleTap = false;
    17.    }
    18.  
    19.    if (doubleTap)
    20.    {
    21.        if (scale == new Vector2(1.0f, 1.0f))
    22.           scale = new Vector2(2.0f, 2.0f);
    23.         else
    24.         {
    25.             scale = new Vector2(1.0f, 1.0f);
    26.             matrixTransform = new Vector3(1, 1, 1);
    27.         }
    28.          doubleTap = false;
    29.    }
    30. }
    Thanks for any help.

    Danny
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can always use .tapCount instead of implementing it yourself.

    --Eric
     
  3. DannyDan

    DannyDan

    Joined:
    Mar 22, 2010
    Posts:
    27
    Hi Eric.

    thanks for the quick answer, but I don't exactly know what you mean. I already tried my if statement with Input.GetTouch(0).tapCount, but I think I miss something.

    Danny
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    .tapCount returns the number of taps for that touch. If it's 2, then it's a double-tap. So you don't have to program your own logic, the OS already does this.

    --Eric
     
  5. DannyDan

    DannyDan

    Joined:
    Mar 22, 2010
    Posts:
    27
    Thanks alot for pointing me in the right direction Eric.
    Never tought it was that easy. :-D
    Now its working just fine.

    Thanks again.

    Danny