Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save asfdfdfd/d918c7b289736aa0c23c72efea203d81 to your computer and use it in GitHub Desktop.
Save asfdfdfd/d918c7b289736aa0c23c72efea203d81 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using Nrjwolf.Tools.AttachAttributes; // https://github.com/Nrjwolf/unity-auto-attach-component-attributes
using TMPro;
using UnityEngine;
[RequireComponent(typeof(TextMeshProUGUI))]
public class TextMeshProTeletypeEffect : MonoBehaviour
{
[GetComponent] [SerializeField] private TextMeshProUGUI m_TextMeshProUGUI;
public TextMeshProUGUI TextMeshProUGUI { get => m_TextMeshProUGUI; }
[Range(0, 1)]
[SerializeField]
private float m_Value = 1;
public float Value
{
get => m_Value;
set
{
m_Value = value;
TextMeshProUGUI.maxVisibleCharacters = (int)(TextMeshProUGUI.textInfo.characterCount * value);
}
}
#if UNITY_EDITOR
void OnValidate()
{
if (!gameObject.activeInHierarchy)
return;
Value = m_Value;
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment