diff options
author | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
---|---|---|
committer | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
commit | 8263edd59284aba390aca011d25b79efecef4c48 (patch) | |
tree | 6346e2afaaabd32156601cafaf20d4ee813befaf /Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs |
Diffstat (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs')
-rw-r--r-- | Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs new file mode 100644 index 0000000..9f72261 --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs @@ -0,0 +1,45 @@ +using UnityEngine.UI; + +namespace UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets +{ + /// <summary> + /// Add this component to a GameObject and call the <see cref="IncrementText"/> method + /// in response to a Unity Event to update a text display to count up with each event. + /// </summary> + public class IncrementUIText : MonoBehaviour + { + [SerializeField] + [Tooltip("The Text component this behavior uses to display the incremented value.")] + Text m_Text; + + /// <summary> + /// The Text component this behavior uses to display the incremented value. + /// </summary> + public Text text + { + get => m_Text; + set => m_Text = value; + } + + int m_Count; + + /// <summary> + /// See <see cref="MonoBehaviour"/>. + /// </summary> + 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); + } + + /// <summary> + /// Increment the string message of the Text component. + /// </summary> + public void IncrementText() + { + m_Count += 1; + if (m_Text != null) + m_Text.text = m_Count.ToString(); + } + } +} |