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

public class Digitador : MonoBehaviour {

    public string msg = "mensagem";
    private Text textComp;
    public float delayInicial = 2f;
    public float delayDigitacao= 0.01f;
    
	void Start () {
        StartCoroutine("TypeIn");
	}
	void Awake () {
        textComp = GetComponent<Text>();
	}
	void FixedUpdate(){
		DiminuirFonte ();
	}
    public IEnumerator TypeIn()
    {
        yield return new WaitForSeconds(delayInicial);

        for(int i = 0; i<msg.Length;i++){
            textComp.text = msg.Substring(0,i);
            //GetComponent<AudioSource>().PlayOneShot(som);
            yield return new WaitForSeconds(delayDigitacao);
        }
    }
    public IEnumerator TypeOff()
    {
        for (int i = msg.Length; i >= 0; i--)
        {
            textComp.text = msg.Substring(0, i);
            yield return new WaitForSeconds(delayDigitacao);
        }
    }
	void DiminuirFonte(){
		if (Screen.width <= 800 || Screen.height<=600) {
			textComp.fontSize = 15;
		}else{
			textComp.fontSize = 19;
		}
	}
}
