using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
    public Word word;
    public TypeRepair typeRepair;
    public Animator transitionAnim;
    public GameObject sceneTransition;
    // Start is called before the first frame update
    // void Start()
    // {

    // }

    // Update is called once per frame
    void Update()
    {
        print("wordindex = " + word.wordIndex);
        print("typeindex = " + word.typeIndex);
    }
    public void NextLevel()
    {
        Time.timeScale = 1;
        if (typeRepair != null) typeRepair.mashIndex = 0;
        if (word != null)
        {
            word.wordIndex = 0;
            word.typeIndex = 0;
        }

        StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
    }

    IEnumerator LoadLevel(int levelIndex)
    {
        enable_scene_transition();
        transitionAnim.SetTrigger("start");
        yield return new WaitForSeconds(1f);
        SceneManager.LoadScene(levelIndex);
    }

    public void RestartLevel()
    {
        Time.timeScale = 1;
        if (typeRepair != null) typeRepair.mashIndex = 0;
        if (word != null)
        {
            word.wordIndex = 0;
            word.typeIndex = 0;
        }

        StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex));

    }

    public void disable_scene_transition()
    {
        sceneTransition.SetActive(false);
    }

    public void enable_scene_transition()
    {
        sceneTransition.SetActive(true);
    }
}
