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

public class LevelLoader : MonoBehaviour{

    public static LevelLoader Instance;

    public Animator transition;
    public float transitionTime = 1f;

    // Start is called before the first frame update
    void Awake(){
        if(Instance == null){
            Instance = this;
        }
    }

    void Start(){
        Time.timeScale = 0;
        StartCoroutine(EnableTimeScale());
    }

    public void LoadLevel(string scene){
        StartCoroutine(LevelTransition(scene));
    }

    IEnumerator EnableTimeScale(){
        yield return new WaitForSecondsRealtime(transitionTime);
        Time.timeScale = 1;
    }

    IEnumerator LevelTransition(string scene){
        transition.SetTrigger("Start");
        Time.timeScale = 0;
        yield return new WaitForSecondsRealtime(transitionTime);
        SceneManager.LoadScene(scene);
    }
}
