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

public class Dialogmeu : MonoBehaviour
{
    public TextMeshProUGUI textDisplay;
    public string[] sentences;
    private int index;
    public float typingSpeed;

    public GameObject continueButton;
    public GameObject playButton;
    private AudioSource source;
    private AudioSource letra;

    private void Start()
    {
        source = GetComponent<AudioSource>();
        letra = GetComponent<AudioSource>();
        StartCoroutine(Type());       
    
    }

    private void Update()
    {
       if (textDisplay.text == sentences[index])
        {
            continueButton.SetActive(true);
        }
    }

    IEnumerator Type()
    {
        foreach (char letter in sentences[index].ToCharArray())
        {
            textDisplay.text += letter;
            source.Play();
            yield return new WaitForSeconds(0.05f);            
        }
    }

    public void NextSentence()
    {
        source.Play();
        continueButton.SetActive(false);

        if (index < sentences.Length - 1)
        {
            index++;
            textDisplay.text = "";
            StartCoroutine(Type());
        } else
        { 
            textDisplay.text = "";            
        }
    }

    public void nextLevelEsgoto()
    {
        SceneManager.LoadScene("Esgoto");
    }

    public void nextLevelFloresta()
    {
        SceneManager.LoadScene("Floresta");
    }

    public void nextLevelBoss()
    {
        SceneManager.LoadScene("Boss");
    }

    public void nextLevelMenu()
    {
        SceneManager.LoadScene("MainMenu");
    }
}
