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

public class LevelManager : MonoBehaviour {

    public static LevelManager instance = null; //Static instance of Levelmanager which allows it to be accessed by any other script.

    private void Update()
    {
        if (CreateObject.playerDead == true)
        { SceneManager.LoadScene("End"); CreateObject.playerDead = false; }
    }

    private void Awake()
    {
        

        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
       
    }

    //referenced to load next scene in buildorder.
    public static void LoadNextLevel()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    
    }
    //referenced to load scene by name.
    public static void LoadLevelByName(string name)
    {
        SceneManager.LoadScene(name);
        
    }

    public void LoadEndScene()
    {
        SceneManager.LoadScene("End");
    }

    public void LoadScenewithDelay(float delay)
    {
        Invoke("LoadEndScene", delay);
    }

    

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

    public void SceneLoadByName(string name)
    {
        SceneManager.LoadScene(name);
    }

    public void SceneLoadNext()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
}
