title: Unity: Multitouch with two Different Scripts
body: <p>I am trying to allow multitouch in my game.. I have two scripts, one that handles the camera rotation, and another that handles the GUITexture clicks. The issue is, when someone is moving the camera, they are not able to also push the GUITexture (to fire the bullet).</p>
  
  <p>I have tried multiple methods of merging the two scripts, but I am not getting it to work.. I have found some methods to do the actual multitouch, I am just not sure how to incorporate it into my game (since I use multiple scripts).. Here is the link to the multitouch info: <a href="http://answers.unity3d.com/questions/167750/how-does-multi-touch-work.html" rel="nofollow">http://answers.unity3d.com/questions/167750/how-does-multi-touch-work.html</a></p>
  
  <p>Thanks!!</p>
  
  <p>EDIT (Here are the scripts):</p>
  
  <p>Fire Button Script: </p>
  
  <pre><code>#pragma strict
  //Fire Button Vars
  var myImg : GUITexture;
   var touches = Input.touches;
  var newBullet : Rigidbody;
  var throwSpeed : float = 30.0;
  
  function Start () {
  
  }
  
  function Update () {
  
  var tapCount = Input.touchCount;
  if(tapCount &gt; 1) {
       var touch1 = Input.GetTouch(0);
       var touch2 = Input.GetTouch(1);
  
       //Fire Button
       if (myImg.HitTest(Input.GetTouch(1).position))
      {
         if(Input.GetTouch(1).phase==TouchPhase.Began)
         {
           print("Touch has began on image");
           var newBullet : Rigidbody = Instantiate(newBullet, transform.position, transform.rotation);
  newBullet.velocity = transform.forward * throwSpeed;
         }
         if(Input.GetTouch(1).phase==TouchPhase.Stationary)
         {
           print("Touch is on image");
         }
         if(Input.GetTouch(1).phase==TouchPhase.Moved)
         {
           print("Touch is moving on image");
         }
         if(Input.GetTouch(1).phase==TouchPhase.Ended)
         {
           print("Touch has been ended on image");
         }else{
  //            if (myImg.HitTest(Input.GetTouch(1).position))
  //    {
  //       if(Input.GetTouch(1).phase==TouchPhase.Began)
  /*       {
           print("Touch has began on image");
           var newBullet2 : Rigidbody = Instantiate(newBullet, transform.position, transform.rotation);
  newBullet.velocity = transform.forward * throwSpeed;
         }
         if(Input.GetTouch(0).phase==TouchPhase.Stationary)
         {
           print("Touch is on image");
         }
         if(Input.GetTouch(0).phase==TouchPhase.Moved)
         {
           print("Touch is moving on image");
         }
         if(Input.GetTouch(0).phase==TouchPhase.Ended)
         {
           print("Touch has been ended on image");
         }
  */       }
         }
  
  }
  }
  </code></pre>
  
  <p>Camera rotate script (Also, the script below only works when you drag your finger on the terrain or something "solid". It doesn't work if you just empty space (ex. Sky)... Any ways to have it works anywhere when someone touches the screen?): </p>
  
  <pre><code>#pragma strict
  
  var targetItem : GameObject;
  var GUICamera : Camera;
  var ambient : GameObject;
  var max = 90;
  var min = 270;
  
  /********Rotation Variables*********/
  var rotationRate : float = 1.0;
  private var wasRotating;
  
  /************Scrolling inertia variables************/
  private var scrollPosition : Vector2 = Vector2.zero;
  private var scrollVelocity : float = 0;
  private var timeTouchPhaseEnded: float;
  private var inertiaDuration : float = 0.5f;
  
  private var itemInertiaDuration : float = 1.0f;
  private var itemTimeTouchPhaseEnded: float;
  private var rotateVelocityX : float = 0;
  private var rotateVelocityY : float = 0;
  
  
  var hit: RaycastHit;
  
  private var layerMask = (1 &lt;&lt;  8) | (1 &lt;&lt; 2);
  //private var layerMask = (1 &lt;&lt;  0);
  
  
  function Start()
  {
      layerMask =~ layerMask;    
  }
  
  function FixedUpdate()
  {
  
      if (Input.touchCount &gt; 0) 
      {   //  If there are touches...
           var theTouch : Touch = Input.GetTouch(0);       //    Cache Touch (0)
  
           var ray = Camera.main.ScreenPointToRay(theTouch.position);
           var GUIRayq = GUICamera.ScreenPointToRay(theTouch.position);
  
  
              if(Physics.Raycast(ray,hit,50,layerMask))
              { 
  
                  if(Input.touchCount == 1)
                   {
  
                     if (theTouch.phase == TouchPhase.Began) 
                        {
                          wasRotating = false; 
                        }     
  
                        if (theTouch.phase == TouchPhase.Moved) 
                        {
  
                          targetItem.transform.Rotate(0, theTouch.deltaPosition.x * rotationRate,0,Space.World);
                          wasRotating = true;
  
                          var angle = theTouch.deltaPosition.x * rotationRate;
  
                          if (angle &gt; max){
                              angle = max;
                          }
                          else if (angle &lt; min){
                              angle = min;
                          }
  
                        }      
  
           }
  
  
  
  
  
      }
      }
      }
  </code></pre>