Skip to content

Instantly share code, notes, and snippets.

@brihernandez
Last active January 18, 2021 18:21
Show Gist options
  • Save brihernandez/ece5a337e0ad30cafc0aae86a854aaa8 to your computer and use it in GitHub Desktop.
Save brihernandez/ece5a337e0ad30cafc0aae86a854aaa8 to your computer and use it in GitHub Desktop.
Set the text of a button in a more convenient and lazy way.
using UnityEngine.UI;
public static class UGUIButtonExtensions
{
public static void SetTextTMPro(this Button button, string text)
{
button.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = text;
}
public static void SetTextUGUI(this Button button, string text)
{
button.GetComponentInChildren<Text>().text = text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment