Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    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...