using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour {

    public List<GameObject> buildings;
    public string sceneToLoad;

    public float nextLevelDelay;
	
	void Update () {

        //INFINI MODE PLZ
        //if all the buildings are destroyed load the next level
        if (buildings.Count == 0) {
            //load next level after a delay
            Invoke("LoadScene", nextLevelDelay);
        }

        for (int i = 0; i < buildings.Count; i++) {
            if (buildings[i] == null) {
                buildings.RemoveAt(i);
            }
        }
    }

    void LoadScene() {
        SceneManager.LoadScene(sceneToLoad);
    }
}
