- Home /
Question by
GragGunner · Apr 28, 2017 at 05:10 AM ·
ui2d game
Display "Typewriter Text Effect" when a bool is set to true in another script.
Hello! I have a script that I'm trying to write and I could use some help :)
What I am trying to achieve is text that is written with a "typewriter effect" (one letter at a time etc) but I want it to only play when a bool in another script I have is set to true. (the bool plays an animation that turns the text on) The problem is the bool is in another script.
Right now the text plays at the start regardless of if the bool is true or not... Here is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DialogueEffect : MonoBehaviour
{
public float delay = 0.1f;
public string fullText;
private string currentText = "";
//public GameObject NPC;
// Use this for initialization
void Start ()
{
if (GameObject.Find("Characters_Sam_Close_01").GetComponent<TriggerAnimator>().TriggerAnim)
{
print("test");
StartCoroutine(ShowText());
}
}
IEnumerator ShowText()
{
for(int i = 0; i < fullText.Length; i++)
{
currentText = fullText.Substring(0,i);
this.GetComponent<Text>().text = currentText;
yield return new WaitForSeconds(delay);
}
}
}
Comment