Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Last active August 22, 2023 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SiarheiPilat/e4fa93c97d31d8d0e2d18f34e0e2abe9 to your computer and use it in GitHub Desktop.
Save SiarheiPilat/e4fa93c97d31d8d0e2d18f34e0e2abe9 to your computer and use it in GitHub Desktop.
Replacement for a TextMeshPRO button that will automatically change button text.
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// Original: https://gist.github.com/SiarheiPilat/e4fa93c97d31d8d0e2d18f34e0e2abe9
/// Author: Siarhei Pilat
/// Date: 29-05-2022
/// License: MIT
public class CoolButton : MonoBehaviour
{
public NameChangeButton ()
{
UnityEditor.EditorApplication.hierarchyChanged += OnHierarchyChanged;
}
private void OnHierarchyChanged ()
{
try
{
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = gameObject.name.Replace("button_", "");
}
catch (MissingReferenceException e) { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment