title: How to detect touch in Unity Game Engine (2D)
body: <p>I have a bomb and want it to explode when touched.  I just tried implementing this with ray-casting but something isn't working. I'm using unity 2d settings. </p>
  
  <p>Also I'm programming this on a computer(of course) so is there some setting I have to set to make it recognize mouse clicks as touches?</p>
  
  <pre><code>#pragma strict
  var explosion:GameObject;
  
  
  function Update () {
      for (var i = 0; i &lt; Input.touchCount; i++) {
          if (Input.GetTouch(i).phase == TouchPhase.Began) {
  
              // Construct a ray from the current touch coordinates
              var pos:Vector3 = Camera.main.ScreenToWorldPoint (Input.mousePosition);
              var hitInfo:RaycastHit2D = Physics2D.Raycast(pos, Vector2.zero);
              if (hitInfo != null &amp;&amp; hitInfo.collider != null) {
                  Debug.Log ("I'm hitting "+hitInfo.collider.name);
                  var whatsHit:GameObject = hitInfo.collider.gameObject;
  
                  if(whatsHit.CompareTag("bomb")){
                      whatsHit.GetComponent(BombScript).Explode(whatsHit.transform.position);
                  }
              } else {
                  Debug.Log("hitting nothing");
              }
          }
      }
  }
  
  function Explode(pos:Vector3){
      GameObject.FindGameObjectWithTag("GameController").GetComponent(BombSpawner).spawnBomb = true;
      Instantiate(explosion, pos, Quaternion.identity);
      Destroy (this.gameObject);
  }
  </code></pre>