Unity Slider Label Text

Need a slider in your game or app and want text on the handle?

The setup for this is pretty simple, you’ll need a slider, a label and a script..

The Slider

Create a slider.. then select a minimum and maximum value.  For the slider above, I’ve also checked “whole numbers”.

The Label

Once you’ve created the slider, find the Handle child.

Create a new Text (or ideally a TextMeshPro – Text) object under the Handle.

Center the text object, and set the color to something that works well with your handle.

And finally, add this script to the text (or textmeshpro text) object..

Code

Note: If you don’t use TextMeshPro (which you should), you’ll need to change the references to just be “Text” & remove the top using statement.

Formatting

The default format for the script above shows a degrees symbol.  You can modify that by editing the FormatText field.  The code uses string.Format, and the {0} is replace by the actual value.