using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Typer : MonoBehaviour
{
    public Text Target;
    public AudioSource AudioSource;
    public string[] Text = {"P ","L ","E ","A ", "S ", "E ", "\n", "S ", "I ", "N ", "E ", "\n", "H ", "E ", "R ", "E" };
    public AudioClip ClickSound;
    public AudioClip ReturnSound;
    public float DelayMin;
    public float DelayMax;
	// Use this for initialization
	void Start ()
	{
	    StartCoroutine(Type());
	}

    IEnumerator Type()
    {
        foreach (var s in Text)
        {
            Target.text += s;
            if (s.Contains("\n"))
                AudioSource.clip = ReturnSound;
            else
                AudioSource.clip = ClickSound;
            AudioSource.Stop();
            AudioSource.pitch = Random.Range(0.9f, 1.1f);
            AudioSource.Play();
            yield return new WaitForSeconds(Random.Range(DelayMin, DelayMax));
        }
        yield return null;
    }
}
