using UnityEngine; using System.Collections; namespace TMPro.Examples { public class TeleType : MonoBehaviour { //[Range(0, 100)] //public int RevealSpeed = 50; private string label01 = "Example of using <#ffa000>Graphics Inline with Text in TextMesh<#40a0ff>Pro and Unity"; private string label02 = "Example of using <#ffa000>Graphics Inline with Text in TextMesh<#40a0ff>Pro and Unity"; private TMP_Text m_textMeshPro; void Awake() { // Get Reference to TextMeshPro Component m_textMeshPro = GetComponent(); m_textMeshPro.text = label01; m_textMeshPro.enableWordWrapping = true; m_textMeshPro.alignment = TextAlignmentOptions.Top; //if (GetComponentInParent(typeof(Canvas)) as Canvas == null) //{ // GameObject canvas = new GameObject("Canvas", typeof(Canvas)); // gameObject.transform.SetParent(canvas.transform); // canvas.GetComponent().renderMode = RenderMode.ScreenSpaceOverlay; // // Set RectTransform Size // gameObject.GetComponent().sizeDelta = new Vector2(500, 300); // m_textMeshPro.fontSize = 48; //} } IEnumerator Start() { // Force and update of the mesh to get valid information. m_textMeshPro.ForceMeshUpdate(); int totalVisibleCharacters = m_textMeshPro.textInfo.characterCount; // Get # of Visible Character in text object int counter = 0; int visibleCount = 0; while (true) { visibleCount = counter % (totalVisibleCharacters + 1); m_textMeshPro.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display? // Once the last character has been revealed, wait 1.0 second and start over. if (visibleCount >= totalVisibleCharacters) { yield return new WaitForSeconds(1.0f); m_textMeshPro.text = label02; yield return new WaitForSeconds(1.0f); m_textMeshPro.text = label01; yield return new WaitForSeconds(1.0f); } counter += 1; yield return new WaitForSeconds(0.05f); } //Debug.Log("Done revealing the text."); } } }