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

public class SceneLoader : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void LoadScene(string sceneName)
    {
        StartPlaySound();
        SceneManager.LoadScene(sceneName);
    }

    public void StartPlaySound()
    {
        playsound ps = GameObject.Find("bgm").GetComponent<playsound>();
        ps.play();
    }

    public void SuccessNextInMainGameScene()
    {
        StartPlaySound();
        string scene_name = SceneManager.GetActiveScene().name;
        if (scene_name.Contains("GameScene_lv1"))
        {
            SceneManager.LoadScene("GameScene_lv2");
        }else if(scene_name.Contains("GameScene_lv2"))
        {
            SceneManager.LoadScene("DialogIntro_2");
        }
    }

    public void FailRestartInMainGameScene()
    {
        StartPlaySound();
        string scene_name = SceneManager.GetActiveScene().name;
        if (!scene_name.Contains("restart"))
        {
            SceneManager.LoadScene(scene_name+"_restart");
        }
        if (scene_name.Contains("restart"))
        {
            string[] temp = scene_name.Split('_');
            SceneManager.LoadScene(temp[0] + "_" + temp[1]);
        }
    }
}
