Skip to content

Instantly share code, notes, and snippets.

@ninpl
Created May 30, 2017 19:51
Show Gist options
  • Select an option

  • Save ninpl/17ea3ac6e4883b0d0526a4425258054e to your computer and use it in GitHub Desktop.

Select an option

Save ninpl/17ea3ac6e4883b0d0526a4425258054e to your computer and use it in GitHub Desktop.
Efecto de TypeWriter en Unity3d de un texto
// ┌∩┐(◣_◢)┌∩┐
// \\
// UITextTypeWriter.cs (29/05/2017) \\
// Autor: Antonio Mateo (Moon Antonio) antoniomt.moon@gmail.com \\
// Descripcion: Controla el Typewriter de un texto \\
// Fecha Mod: 29/05/2017 \\
// Ultima Mod: Version Inicial \\
//******************************************************************************\\
#region Librerias
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
#endregion
namespace MoonAntonio.UI.Efectos
{
/// <summary>
/// <para>Controla el Typewriter de un texto</para>
/// </summary>
[AddComponentMenu("MoonAntonio/UI/Efectos/UITextTypeWriter")]
public class UITextTypeWriter : MonoBehaviour
{
#region Variables Privadas
/// <summary>
/// <para>Componente Text</para>
/// </summary>
private Text txt; // Componente Text
/// <summary>
/// <para>Texto que mostrar</para>
/// </summary>
private string parrafo; // Texto que mostrar
#endregion
#region Inicializadores
/// <summary>
/// <para>Inicializador de <see cref="UITextTypeWriter"/></para>
/// </summary>
private void Init()// Inicializador de UITextTypeWriter
{
txt = GetComponent<Text>();
parrafo = txt.text;
txt.text = "";
StartCoroutine("PlayText");
}
#endregion
#region Actualizadores
/// <summary>
/// <para>Crea un efecto TypeWriter</para>
/// </summary>
/// <returns></returns>
IEnumerator PlayText()// Crea un efecto TypeWriter
{
foreach (char c in parrafo)
{
txt.text += c;
yield return new WaitForSeconds(0.125f);
}
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment