Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Understanding UnityEngine.Input.touches

Discussion in 'Scripting' started by Reapa, Sep 3, 2015.

  1. Reapa

    Reapa

    Joined:
    May 2, 2013
    Posts:
    26
    Given the following inside "void Update()":

    Code (CSharp):
    1. Debug.Log("////START TOUCHLOG////");
    2. foreach (var touch in UnityEngine.Input.touches)
    3. {
    4.     Debug.Log("T" + touch.fingerId + ": " + touch.phase + ", " + touch.position);
    5. }
    6. Debug.Log("////END TOUCHLOG////");
    Using 3 of my fingers not touching close to:

    1. Touch first finger
    2. Touch second finger elsewhere
    3. Touch third finger elsewhere
    4. Repeatably tap first and second finger on the same spot.

    _
    Can someone explain why these loggings occur:

    A) Same touch ID appears twice?

    _
    B) No "end" event for T1. T2 becomes T1 next frame.
    This issue occurs when building to WebGL and running on Windows 8 in chrome using the touch screen.

    This issue does not occur when building to Windows and running on Windows 8 using the touch screen.
     
  2. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    I also have this problem at coding a co op game with touch screen.

    The touch id i changed every time a finger is released, so i had to check the fingerID in the touch data which doesn't change.

    1st Finger Pushed:
    TouchID 0 | Finger ID 0

    2nd Finger Pushed:
    TouchID 0 | Finger ID 0 (1stFinger)
    TouchID 1 | Finger ID 1 (2ndFinger)

    3rd Finger Pushed:
    TouchID 0 | Finger ID 0 (1stFinger)
    TouchID 1 | Finger ID 1 (2ndFinger)
    TouchID 2 | Finger ID 2 (3rdFinger)

    releasing 2nd Finger:
    TouchID 0 | Finger ID 0 (1stFinger)
    TouchID 1 | Finger ID 2 (3rdFinger)

    releasing 1st Finger:
    TouchID 0 | Finger ID 2 (3rdFinger)


    Code (CSharp):
    1. Input.GetTouch(TouchID).fingerId
    as far as i can remember putting again a finger down the others are pushed back again like

    new finger
    TouchID 0 | Finger ID 0 (newFinger)
    TouchID 1 | Finger ID 2 (3rdFinger)

    new finger 2nd
    TouchID 0 | Finger ID 0 (newFinger)
    TouchID 1 | Finger ID 1 (2ndnewFinger)
    TouchID 2 | Finger ID 2 (3rdFinger)
     
    Last edited: Sep 3, 2015
  3. Reapa

    Reapa

    Joined:
    May 2, 2013
    Posts:
    26
    Only problem is I was using finger ID, which shouldn't change as you've mentioned.