title: (Unity 2D) Destroy instantiated prefab when it goes off screen?
body: <p>Im making a 2D Game in Unity 2D(4.3), and I need to destroy the prefabs that get instantiated when those prefabs go off the screen. I have written some code to spawn the Objects, but then I want to delete those prefabs when they go off screen. 
  Here is the code I have written so far. </p>
  
  <p>To Generate prefab (C#):</p>
  
  <pre><code>void Update () {
      float y = Random.Range(-4.53f, 2.207f);
      if(x &lt; 2000) {
          Instantiate(obstacle, new Vector3(y, x * 6.0f, 0),Quaternion.identity);
          x++;
      }
      //Debug.Log(x);
  
  }
  </code></pre>
  
  <p>To destroy the prefab(C#):</p>
  
  <pre><code>    /*************************************************************************************************
       * GET INSTANTIATED OBSTACLE
       * AND DESTROY IT ON EXIT
       * TO SAVE MEMORY
      **************************************************************************************************/
      GameObject clone = (GameObject)Instantiate (obstacle);
  
      /*if(clone.transform.position.y == -11)
      {
          Destroy(clone);
          Debug.Log("Destroy");
      }*/
  
      Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
      if (screenPosition.y &gt; Screen.height || screenPosition.y &lt; 0)
      {
          Destroy(gameObject);
          Debug.Log("Destroy");
      }
  </code></pre>
  
  <p>However, the code to destroy the object is not working, but is not getting an error either. It does output "Destroy" after the prefabs go off screen so I know its something wrong with the code to destroy them.</p>
  
  <p>Thanks</p>