Sliders, toggles, and dropdowns
Let players choose a value with a slider, turn an option on or off with a toggle, or pick from a list with a dropdown in your Unity Spark UI.
Read time 3 minutesLast updated 3 hours ago
Sliders, toggles, and dropdowns let players change settings, such as volume, music on or off, or difficulty. For more information about choosing an element, refer to Choose an element.
These elements change a value when the player uses them, but your game decides what the value does. To connect a control to your game, ask the AI assistant, for example, You can also use a script.
Make the volume slider change the music volume.Settings every control shares
Buttons, sliders, toggles, input fields, and scrollbars share the following settings.
Setting | Description |
|---|---|
| Interactable | Sets whether the player can use the control. When Interactable is disabled, the control shows its Disabled Color. |
| Colors | Sets the tint for each state: Normal Color, Highlighted Color (when the pointer is over it), Pressed Color, Selected Color, and Disabled Color. Color Multiplier brightens every state, and Fade Duration sets how long a change takes. |
Slider
A slider is a handle that the player drags along a track to choose a value between a minimum and a maximum. A new slider has a track, a fill that grows as the value increases, and a handle. It has no label, so add a Text element next to it.
Slider properties
The Slider component contains the following main settings.
Setting | Description |
|---|---|
| Direction | Sets which way the value increases, for example, from left to right. |
| Min Value and Max Value | Sets the range of values. By default, |
| Whole Numbers | Allows only whole numbers, for example, for a difficulty level from |
| Value | Sets the current value. |
To respond when the player drags the slider, pass a function to . The function receives the new value.
OnValueChangedlocal function onVolumeChanged(value) -- use the new value, for example to set the music volumeendvolumeSlider:OnValueChanged(onVolumeChanged)
Pass a function that you define in the same script. Don't pass , because the event calls the function you give it.
selfTo change the value from a script without triggering , use . Don't use a slider only to display a value, because the player can drag it. Use a progress bar instead.
OnValueChangedSetValueWithoutNotifyToggle
A toggle is a checkbox with a label that the player turns on or off. A new toggle shows the label and starts turned on.
ToggleToggle properties
The Toggle component contains the following main settings.
Setting | Description |
|---|---|
| Is On | Determines whether the toggle is on. |
| Graphic | Sets the check mark that shows when the toggle is on. |
To respond when the player turns the toggle on or off, pass a function to . The function receives when the toggle is on.
OnValueChangedtrueTo let the player choose only one option from a set of toggles, such as Easy, Normal, or Hard, the toggles need a ToggleGroup component. Ask the assistant to set it up, for example, In the ToggleGroup component, enable Allow Switch Off to let the player leave every toggle in the group off.
Make the Easy, Normal, and Hard toggles a group where only one can be on.Dropdown
A dropdown shows the current option. When the player selects it, a list opens so they can pick another option. A new dropdown has the options , , and .
Option AOption BOption CTo set the options, ask the assistant, for example, You can also set them in a script with and . The dropdown's is the position of the selected option in the list, starting at . To respond when the player picks an option, pass a function to .
Make the quality dropdown list Low, Medium, and High.ClearOptionsAddOptionvalue0OnValueChanged