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

public class LevelSelect : MonoBehaviour
{

    public GameObject levelButtonItem;

    bool initialized = false;
    void Awake()
    {
        if (initialized)
            return;
        initialized = true;
        for (int i = 1; i < SceneManager.sceneCountInBuildSettings; i++)
        {
            print(i);
            GameObject go = Instantiate<GameObject>(levelButtonItem);
            go.transform.SetParent(levelButtonItem.transform.parent, false);
            go.GetComponentInChildren<Text>().text = i + "";
            Button button = go.GetComponent<Button>();
            int tmp = i;
            button.onClick.AddListener(() =>
            {
                GameController.Instance.OnLevelSelected(tmp);
            });

            go.SetActive(true);

        }
    }

}
