Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

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

public class CharacterInnerThoughts : MonoBehaviour
{
    public Text textDisplay;

    public string[] sentences;

    private int index;

    public float speed;

    public float destroyTime;

    public GameObject theCanvas;

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

    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.gameObject.tag == "Player")
        {
            StartCoroutine(Type());
        }
    }

    void RemoveText()
    {
        Destroy(textDisplay, destroyTime);
        Destroy(theCanvas, destroyTime);
    }
}