using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class DialogLevel1 : MonoBehaviour
{
    public Text text;
    public string[] dialogs;
    private int index;
    private float letterPause = 0.05f;
    public GameObject continueButton;
    public GameObject yesButton;
    public GameObject noButton;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Type());
        SceneManager.LoadScene("Progress", LoadSceneMode.Additive);
    }

    // Update is called once per frame
    void Update()
    {
        if (text.text == dialogs[index])
        {
            continueButton.SetActive(true);
        }
    }

     IEnumerator Type() {
         foreach (char letter in dialogs[index].ToCharArray()) 
         {
            text.text += letter;
            yield return new WaitForSeconds(letterPause);
         }
     }

     public void NextDialog()
     {
         continueButton.SetActive(false);
         if (index < dialogs.Length -1)
         {
             index++;
             text.text = "";
             StartCoroutine(Type());
         }
         else
         {
            text.text = "";
            continueButton.SetActive(false);
            yesButton.SetActive(true);
            noButton.SetActive(true);

         }
     }

     public void YesChoise()
     {
        SceneManager.LoadScene("Level1AfterCutsceneYes");
     }
     public void NoChoise()
     {
        Progress.instance.score = -20;
        SceneManager.LoadScene("Level1AfterCutsceneNo");
     }


}
