Displaying the value of an interactive UI Slider
This recipe illustrates how to create an interactive UI Slider, and execute a C# method each time the user changes the UI Slider value:

How to do it...
To create a UI Slider and display its value on the screen, follow these steps:
- Create a new 2D project.
- Add a UI Text GameObject to the scene with a Font size of
30
and placeholder text, such asslider value here
(this text will be replaced with the slider value when the scene starts). Set Horizontal- and Vertical- Overflow to Overflow. - In the Hierarchy add a UI Slider GameObject to the scene – choose menu:
GameObject | UI | Slider
. - In the Inspector, modify the settings for the position of the UI Slider GameObject's Rect Transform to the top-middle part of the screen.
- In the Inspector, modify settings for Position of the UI Text'sRect Transform to just below the slider (top, middle, then Pos Y =
-30
). - In the Inspector, set the UI Slider'sMin Value to
0
, the Max Value to20
, and check the Whole Numbers...