Skip to content

Instantly share code, notes, and snippets.

@Nrjwolf
Created July 23, 2020 09:58
Show Gist options
  • Save Nrjwolf/1ac404c3cba55cfc7fe1865d96f74c00 to your computer and use it in GitHub Desktop.
Save Nrjwolf/1ac404c3cba55cfc7fe1865d96f74c00 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
}
@Nrjwolf
Copy link
Author

Nrjwolf commented Jul 23, 2020

2020-07-23 17-51-15 2020-07-23 18_00_05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment