title: How can I make a destroyer that destroys all the overtaken platforms in unity?
body: <p>I'm doing a unity project for an exam I'm attending, so I'm not really good at unity, hope you can help.
  I'm doing this 2d endless runner game and I created an empty object to set inactive all the platforms that the player has overtaken. The object moves forward and when its position is &gt; than the platform position, it sets it inactive (since destroying them also removes them from the list so it wouldnt work for others platforms of the same kind). My problem is that I've created a list in which I put all the types of my prefabs but the way I did it, it only sets inactive the first prefab of a kind and then stops working.</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class DistruttoreLivelli : MonoBehaviour
  {
      
      public List&lt;GameObject&gt; objs;
      // Start is called before the first frame update
      void Start()
      {
          
      }
  
      // Update is called once per frame
      void Update()
      {
  
          for (int i = 0; i &lt; objs.Count; i++)
          {
              if (objs[i].transform.position.x &lt; transform.position.x)
              {
                  objs[i].SetActive(false);
              }
  
          }
      }
  }
  </code></pre>
  <p>How can I manage to make it go forever? I tried to use a while but it makes unity crash. :/
  Ty for the help!</p>