Created
June 30, 2017 02:06
-
-
Save unity3dcollege/35c9f9f6cbb31e7f632f803b5f712f8b to your computer and use it in GitHub Desktop.
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; | |
using UnityEngine.UI; | |
public class SliderValueText : MonoBehaviour | |
{ | |
[SerializeField] | |
[Tooltip("The text shown will be formatted using this string. {0} is replaced with the actual value")] | |
private string formatText = "{0}°"; | |
private TextMeshProUGUI tmproText; | |
private void Start() | |
{ | |
tmproText = GetComponent<TextMeshProUGUI>(); | |
GetComponentInParent<Slider>().onValueChanged.AddListener(HandleValueChanged); | |
} | |
private void HandleValueChanged(float value) | |
{ | |
tmproText.text = string.Format(formatText, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment