- Home /
 
              This question was 
             closed Nov 23, 2013 at 01:27 PM by 
             ozturkcompany for the following reason: 
             
 
            The question is answered, right answer was accepted
 
               Question by 
               ozturkcompany · Nov 23, 2013 at 11:38 AM · 
                touchdragcube  
              
 
              How to drag two Cubes by Touch At the same time?
Hi, i am trying to drag two cubes by two finger at the same time but cannot get my code work for it.Could anyone hand me a hand here please, i am stuck at this for few weeks not and tried to solve the problem myself but cannot do it.Here is the code i have on each cube.The code also doesn't work when i first put my finger on somewhere else in the screen and then put my second finger on the cube and try to drag it.Also i cannot drag two cubes at the same time.I am blind here cannot see what i did wrong.
Thank you so much in advance!
 #pragma strict
 var touched : boolean;
 var touchId : int;
  
 function Update () {
  
 for(var i = 0; i < Input.touchCount; ++i) {
  
 if(Input.GetTouch(i).phase == TouchPhase.Began) {
  
 var hit : RaycastHit;
 var ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
  
 if(Physics.Raycast(ray, hit)) {
  
 if(hit.collider == transform.collider) {
  
 touched = true;
 touchId = Input.GetTouch(i).fingerId;
  
 }
  
 }
 
 }
  
 if(Input.GetTouch(touchId).phase == TouchPhase.Ended || Input.GetTouch(touchId).phase == TouchPhase.Canceled) {
  
 touched = false;
 touchId = -1;
  
 }
  
 if(Input.GetTouch(touchId).phase == TouchPhase.Moved && touched == true && Input.GetTouch(touchId).deltaPosition.magnitude > 2) {
  
 transform.Translate(Input.GetTouch(touchId).deltaPosition.x * Time.deltaTime, Input.GetTouch(touchId).deltaPosition.y * Time.deltaTime, 0);
  
 }
  
 }
 
 }
 
              
               Comment