Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Problem with Input.GetTouch(0).phase == TouchPhase.Stationary

Discussion in 'Scripting' started by herbie, Sep 28, 2015.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    I have this code:
    Code (JavaScript):
    1. if (Input.touchCount > 0)
    2.     {
    3.         var rayTouchpad = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    4.         var hitTouchpad: RaycastHit;
    5.  
    6.         if (Input.GetTouch(0).phase == TouchPhase.Stationary && Touchpad.Raycast(rayTouchpad, hitTouchpad, Mathf.Infinity))
    7.         {
    8.             fingerOnTouchpad++;
    9.         }
    10.     }
    11.     if (fingerOnTouchpad > fingerOnTouchpadOld)
    12.     {
    13.         test1++;
    14.        
    15.     }
    16.     if (fingerOnTouchpad <= fingerOnTouchpadOld)
    17.     {
    18.         test2++
    19.     }
    20.     fingerOnTouchpadOld = fingerOnTouchpad;
    When I don't have my finger on the Raycast, test2 is increasing. Correct.
    When I put my finger on the Raycast and does not move, test1 is increasing and test2 not. That's also correct.
    But when I put my finger on the Raycast and move it, test2 is increasing. But I don't want that.
    What am I doing wrong?
     
    Last edited: Sep 28, 2015
  2. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Actually, what I want to detect is when the finger is swiped out of the raycast (without lifting up from the screen).
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    that doesn't make sense, the raycast is being cast from where the touch is, the input will never be "out of" the raycast...
     
unityunity