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

trouble with input.touches

Discussion in 'Scripting' started by pretender, Sep 23, 2011.

  1. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    hi everybody, i have some trouble with properly identifying touches on tablet.
    basically i need to have just one tap, tap hold and rotate (or slide) and slide with two fingers...

    the code i have works fine for slide with two fingers. it works when i want to rotate camera
    but when i lift the finger if object is below the finger it will get selected. i want to avoid this

    here is the code:

    Code (csharp):
    1. //IF WE HAVE TWO TOUCHES AND WE HAVE MOVEMENT OF BOTH OF THEM
    2.     if(Input.touchCount>1  Input.GetTouch(0).phase == TouchPhase.Moved  Input.GetTouch(1).phase == TouchPhase.Moved){
    3.    
    4.         distance += Input.GetTouch(0).deltaPosition.y*0.01;
    5.    
    6.     //IF WE HAVE ONE TOUCH AND WE  HAVE MOVEMENT
    7.     }
    8.    
    9.     if(Input.touchCount == 1  Input.GetTouch(0).phase == TouchPhase.Moved) {
    10.    
    11.         touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    12.        
    13.         x += touchDeltaPosition.x * xSpeed*0.003;
    14.         y -= touchDeltaPosition.y * ySpeed*0.003;
    15.        
    16.     }
    17.    
    18.     //IF WE HAVE JUST ONE CLICK
    19.     if(Input.touchCount == 1  Input.GetTouch(0).phase == TouchPhase.Ended){
    20.    
    21.         var hit : RaycastHit;
    22.            
    23.         //CHECK IF WE HIT SOMETHING WITH RAY FROM THE TOUCH POSITION TO INFINITY
    24.         if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.GetTouch(0).position),hit,100)){
    25.                    
    26.             //DO SOMETHING
    27.  
    28.         }
    29.        
    30.     }
    31.    
    any ides appreciated!
     
  2. Doucettej

    Doucettej

    Joined:
    Jan 18, 2010
    Posts:
    85
    Could you possibly add the objects you don;t want selected to a list of sorts and then disregard them if one of them is hit... or just make it so that your ray-cast does not look at those objects at all?

    Jason
     
    Last edited: Jan 27, 2012