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

public class LevelManager : MonoBehaviour {

    public Image img;
    public AnimationCurve fadeCurve;

    public void LoadScene(int scene)
    {
        StartCoroutine(FadeOut(scene));
        
    }
    

    IEnumerator FadeOut(int scene)
    {
        float t = 0f;

        while (t < 1f)
        {
            t += Time.deltaTime;
            float a = fadeCurve.Evaluate(t);
            img.color = new Color(0f, 0f, 0f, a);
            yield return 0;
        }
        SceneManager.LoadScene(scene);
    }

    public void ResetData()
    {
        PlayerPrefs.SetInt("levelReached", 1);
        StartCoroutine(FadeOut(0));
    }

    public void LeaveGame()
    {
        Application.Quit();
    }
}
