two input touch android

Hi everybody i’m creating a game that have two touch controls, my problem is !if i input two touches in my screen i can’t control the two objects anymore I’m stucked here for 24 hours and still can’t find the answer.

Object 1 & Object 2 have a script:

private var dist : float;
private var toDrag : Transform;
private var dragging = false;
private var offset : Vector3;

function Update () {            
        var v3 : Vector3;
        if(Input.touchCount!=1)
        {
        	dragging=false;
        	return;
        }
var        touch:  Touch  = Input.touches[0];
        var pos : Vector3 = touch.position;
        
    if(touch.phase==TouchPhase.Began) {
        var hit : RaycastHit;
        var ray : Ray = Camera.main.ScreenPointToRay(pos); 
        if(Physics.Raycast(ray,hit) && (hit.collider.tag == "Drag"))
        {
             toDrag = hit.transform;
             dist = hit.transform.position.z - Camera.main.transform.position.z;
             v3 = new Vector3(pos.x,pos.y,dist);
             v3 = Camera.main.ScreenToWorldPoint(v3);
             offset = toDrag.position - v3;
             dragging = true;
        }
    }
    if (dragging&&touch.phase==TouchPhase.Moved) {
        v3 = Vector3(Input.mousePosition.x, Input.mousePosition.y, dist);
        v3 = Camera.main.ScreenToWorldPoint(v3);
        toDrag.position = v3 + offset;
    }
    if (dragging && (touch.phase==TouchPhase.Ended||touch.phase==TouchPhase.Canceled)) {
        dragging = false;
    }

   
 }

If you have multitouch events for two or more objects in your scene, that in your script when there is the second touch the first shall work incorrectly. You need to remember the Id of a finger of a contact. I will a little add your script with comments:

 private var dist : float;
 private var toDrag : Transform;
 private var dragging = false;
 private var offset : Vector3;
 private var finId : int = -1; //Id finger which touch of screen

 function Start() {
  Input.multiTouchEnabled = true; //enabled Multitouch
 }

 function Update () {            
  var v3 : Vector3;
  //check all touch events
  for(var touch : Touch in Input.touches) {
   var pos : Vector3 = touch.position;
   if(touch.phase == TouchPhase.Began && finId == -1) { //add check for finger Id
    var hit : RaycastHit;
    var ray : Ray = Camera.main.ScreenPointToRay(pos); 
    if(Physics.Raycast(ray,hit) && (hit.collider.tag == "Drag")) {
     toDrag = hit.transform;
     dist = hit.transform.position.z - Camera.main.transform.position.z;
     v3 = new Vector3(pos.x,pos.y,dist);
     v3 = Camera.main.ScreenToWorldPoint(v3);
     offset = toDrag.position - v3;
     dragging = true;
     finId = touch.fingerId; //store finger Id our touch
    }
   }
   if (dragging && touch.phase == TouchPhase.Moved && finId == touch.fingerId) {
    v3 = Vector3(Input.mousePosition.x, Input.mousePosition.y, dist);
    v3 = Camera.main.ScreenToWorldPoint(v3);
    toDrag.position = v3 + offset;
   }
   if (dragging && fingId == touch.fingerId && (touch.phase == TouchPhase.Ended||touch.phase == TouchPhase.Canceled)) {
    dragging = false;
    finId = -1;
   }
  }
 }

In my opinion, it is better for you to use GUITexture and to work with it. You watch an example of it in my pregoing response. I hope that it will help you.