Skip to content

Instantly share code, notes, and snippets.

@Dssdiego
Last active April 28, 2020 08:50
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 Dssdiego/62ad399d7f5341599f583bb611f6c4c3 to your computer and use it in GitHub Desktop.
Save Dssdiego/62ad399d7f5341599f583bb611f6c4c3 to your computer and use it in GitHub Desktop.
Sets an [IntVariable](https://gist.github.com/Dssdiego/36f331c0460a5187f5ed7a74418d1ed3) to a TextMeshProUI text
using TMPro;
using UnityEngine;
namespace Architecture
{
[RequireComponent(typeof(TextMeshProUGUI))]
public class TextIntSetter : MonoBehaviour
{
private TextMeshProUGUI textUI;
public IntVariable variable;
private void Awake()
{
textUI = GetComponent<TextMeshProUGUI>();
variable.OnChanged += OnChanged;
}
public void OnChanged(int newValue)
{
if (textUI != null)
textUI.SetText(newValue.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment