using UnityEngine.UI; namespace UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets { /// /// Add this component to a GameObject and call the method /// in response to a Unity Event to update a text display to count up with each event. /// public class IncrementUIText : MonoBehaviour { [SerializeField] [Tooltip("The Text component this behavior uses to display the incremented value.")] Text m_Text; /// /// The Text component this behavior uses to display the incremented value. /// public Text text { get => m_Text; set => m_Text = value; } int m_Count; /// /// See . /// protected void Awake() { if (m_Text == null) Debug.LogWarning("Missing required Text component reference. Use the Inspector window to assign which Text component to increment.", this); } /// /// Increment the string message of the Text component. /// public void IncrementText() { m_Count += 1; if (m_Text != null) m_Text.text = m_Count.ToString(); } } }