Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Input.touchCount shows unexisting touch

Discussion in 'Editor & General Support' started by reivendark, Dec 23, 2013.

  1. reivendark

    reivendark

    Joined:
    Dec 23, 2013
    Posts:
    6
    I have some problems with Unity touch input system on my Windows Phone 8 device
    Code (csharp):
    1.  
    2. void Update ()
    3. {
    4. #if UNITY_WP8
    5.         for (int i = 0; i < fingers.Length; i++)
    6.         {
    7.             if (i < Input.touchCount)
    8.             {
    9.                 Vector3 inputVector = Input.GetTouch(i).position;
    10.                 var currentFingerPosition =
    11.                     Camera.main.ScreenToWorldPoint(new Vector3(inputVector.x, inputVector.y, depthZ));
    12.  
    13.                 if (Input.GetTouch(i).phase != TouchPhase.Ended  Input.GetTouch(i).phase != TouchPhase.Canceled)
    14.                 {
    15.                     fingers[i].transform.position = currentFingerPosition;
    16.                 }
    17.                 else
    18.                 {
    19.                     fingers[i].transform.position = _originVector;
    20.                 }
    21.             }
    22.             else
    23.             {
    24.                 fingers[i].transform.position = _originVector;
    25.             }
    26.         }
    27. #endif 
    28. }
    29.  
    where fingers[] is my prefabs with sprites for indicating touches (I use four of them).
    _originVector is simple dummy vector (new Vector3(1000, 0, 0)) for indicator's position reset

    When I make very fast touches on device's screen sometimes finger indicator is getting stuck. And after that it always shows input on screen in place where finger is stuck even if I don't touch screen. (input.touchCount always greater than zero). It can unstuck if I repeat fast taps on screen. Help me please, and sorry for my english:)
     
    Last edited: Dec 24, 2013
  2. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,571
    I find touch phases are very unreliable if you have multitouch enabled. I create a variable that stores the touchCount at the end of the Update. Then I can compare the touchCount to the variable for working out touch phases.
     
  3. reivendark

    reivendark

    Joined:
    Dec 23, 2013
    Posts:
    6
    Thank you so much for your reply:)
     
  4. zedsmith52

    zedsmith52

    Joined:
    May 10, 2017
    Posts:
    9
    Having the same problem here - it seems extremely poor to address this issues by coding around the Unity documented approach - has a fix been provided in later versions of Unity, or is this still faulty?
     
  5. bindon

    bindon

    Joined:
    May 25, 2017
    Posts:
    20
    Still faulty in May 2023, as far as I can tell