Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created June 30, 2017 02:06
Show Gist options
  • Save unity3dcollege/35c9f9f6cbb31e7f632f803b5f712f8b to your computer and use it in GitHub Desktop.
Save unity3dcollege/35c9f9f6cbb31e7f632f803b5f712f8b to your computer and use it in GitHub Desktop.
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