Documentation

Unity Spark

Open Unity Spark

Unity Spark

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,
Make the volume slider change the music volume.
You can also use a script.

Settings every control shares

Buttons, sliders, toggles, input fields, and scrollbars share the following settings.

Setting

Description

InteractableSets whether the player can use the control. When Interactable is disabled, the control shows its Disabled Color.
ColorsSets 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

DirectionSets which way the value increases, for example, from left to right.
Min Value and Max ValueSets the range of values. By default,
0
to
1
.
Whole NumbersAllows only whole numbers, for example, for a difficulty level from
1
to
5
.
ValueSets the current value.
To respond when the player drags the slider, pass a function to
OnValueChanged
. The function receives the new value.
local 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
self
, because the event calls the function you give it.
To change the value from a script without triggering
OnValueChanged
, use
SetValueWithoutNotify
. Don't use a slider only to display a value, because the player can drag it. Use a progress bar instead.

Toggle

A toggle is a checkbox with a label that the player turns on or off. A new toggle shows the label
Toggle
and starts turned on.

Toggle properties

The Toggle component contains the following main settings.

Setting

Description

Is OnDetermines whether the toggle is on.
GraphicSets 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
OnValueChanged
. The function receives
true
when the toggle is on.
To 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,
Make the Easy, Normal, and Hard toggles a group where only one can be on.
In the ToggleGroup component, enable Allow Switch Off to let the player leave every toggle in the group off.
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
Option A
,
Option B
, and
Option C
.
To set the options, ask the assistant, for example,
Make the quality dropdown list Low, Medium, and High.
You can also set them in a script with
ClearOptions
and
AddOption
. The dropdown's
value
is the position of the selected option in the list, starting at
0
. To respond when the player picks an option, pass a function to
OnValueChanged
.

Additional resources