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

public class SceneLoader : MonoBehaviour{

    [System.Serializable] public enum DifficultySelected {Easy, Hard}
    public DifficultySelected difficultySelected;

    Animator anim;

    public static SceneLoader instance;

    void Awake(){
        if(instance == null){
            instance = this;
        }else{
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);

        anim = GetComponent<Animator>();
    }

    public void LoadScene(int scene, DifficultySelected difficulty){
        anim.SetTrigger("FadeOut");
        StartCoroutine(SceneChange(scene, difficulty));
    }

    IEnumerator SceneChange(int scene, DifficultySelected difficulty){
        yield return new WaitForSeconds(1);
        difficultySelected = difficulty;
        AsyncOperation operation = SceneManager.LoadSceneAsync(scene);

        while (!operation.isDone)
            yield return null;
        
        if (operation.isDone){
            anim.SetTrigger("FadeIn");
        }
    }
}
