Last active
April 28, 2020 08:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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