title: Spawn objects in unity
body: <p>I'm writting a small 2D game in Unity with C#. I have built two obstaclespawner which spawn vertical lines. After the lines have been spawned, they move down. One of the spawner is located at the upper left edge and the other one at the upper right edge. Currently, new objects are spawned after a certain time. But my goal is, for example, to spawn a new object on the upper left edge when the object which is spawned on the top right has traveled a certain distance.
  Could this possibly be done via the coordinates of the objects?</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class ObstacleSpawner : MonoBehaviour
  {
      public GameObject[] obstacles;
      public List&lt;GameObject&gt; obstaclesToSpawn = new List &lt;GameObject&gt;();
      int index;
  
      void Awake()
      {
          InitObstacles();
      }
  
      // Start is called before the first frame update
      void Start()
      {
          StartCoroutine (SpawnRandomObstacle ());
      }
  
      // Initialize obstacles
      void InitObstacles()
      {
          index=0;
          for(int i =0; i&lt;obstacles.Length*3;i++){
          GameObject obj = Instantiate(obstacles[index], transform.position, Quaternion.identity);
          obstaclesToSpawn.Add(obj);
          obstaclesToSpawn [i].SetActive (false);
          index++;
  
              if (index == obstacles.Length)
              {
                  index= 0;
              }
          }
      }
  
      IEnumerator SpawnRandomObstacle()
      {
          //Wait a certain time
          yield return new WaitForSeconds(3f);
      }
  
  
              //I want something like this
              (if gameObject.x == -0.99){
  
  
  
              //activate obstacles
              int index = Random.Range(0, obstaclesToSpawn.Count);
  
              while(true){
                  if (!obstaclesToSpawn[index].activeInHierarchy){
                      obstaclesToSpawn[index].SetActive(true);
                      obstaclesToSpawn [index].transform.position = transform.position;
                      break;
                  }else{
                      index = Random.Range (0, obstaclesToSpawn.Count);
                  }
              }
  
              StartCoroutine (SpawnRandomObstacle ());
          }
      }
  </code></pre>