title: Unity prefab array instantiate and destroy
body: <p>I am having a very little problem in my Unity project but can't find a proper help or way to do. I am stuck at point where I have an array of prefab GameObjects and I am trying to instantiate index 1 GameObject and when it destroyed instantiate the next index. Here is how I am doing it. I have two scripts: One to instantiate and other one to destroy it.
  Scripts 1:</p>
  
  <pre><code>public class GameObjectsArray : MonoBehaviour {
  
      public static GameObjectsArray Instance { get; set; }
      public GameObject[] Objects;
      public int i=0;
  
      // Use this for initialization
      void Start()
      {
          InstiatingMethod();
          //Instantiate(Objects[i]);
  
      }
      public void InstiatingMethod()
      {
          Instantiate(Objects[i]);
      }
  }
  </code></pre>
  
  <p>Scripts 2:</p>
  
  <pre><code>public class CheckDestroy : MonoBehaviour {
  
      //public GameObject[] Objects;
      //int i;
  
      // Use this for initialization
      void Start () {
  
          Debug.Log("executed");
  
          //Objects = GameObject.FindGameObjectsWithTag("Player");
  
          //OnMouseDown();
  
          //Instantiate(Objects[i], transform.position, transform.rotation);
  
      }
  
      // Update is called once per frame
      void Update () {
  
          if (Input.GetMouseButtonDown(0))
          {
              RaycastHit hit;
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
              if (Physics.Raycast(ray, out hit))
              {
                  BoxCollider boxCollider = hit.collider as BoxCollider;
  
                  if (boxCollider != null)
                  {
                      GameObjectsArray.Instance.i++;
                      GameObjectsArray.Instance.InstiatingMethod();
  
                      Destroy(boxCollider.gameObject);
  
                  }
  
              }
          }
      }
  }
  </code></pre>