Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Toggle

A Toggle is a clickable element that represents a boolean value.
Read time 10 minutesLast updated 2 days ago

Definition

[UxmlElement(libraryPath = "Controls")][Icon("UIToolkit/Icons/Toggle.png")]public class Toggle : BaseBoolField, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle, IBindable, IMixedValueSupport, INotifyValueChanged<bool>

Remarks

A Toggle control consists of a label and an input field. The input field contains a sprite for the control. By default, this is a checkbox (Unity does not provide a separate checkbox control type) in all of its possible states, for example, normal, hovered, checked, and unchecked. You can style a Toggle control to change its appearance to something else, for example, an on/off switch.
When a Toggle is clicked, its state alternates between between true and false. You can also think of these states as on and off, or enabled and disabled.
To bind the Toggle's state to a boolean variable, set the
binding-path
property in a UI Document (.uxml file), or the C#
bindingPath
to the variable name.
For more information, refer to UXML element Toggle.

Static Fields

Value

Description

checkmarkUssClassNameUSS class name of Images in Toggle elements.
inputUssClassNameUSS class name of input elements in Toggle elements.
labelUssClassNameUSS class name for Labels in Toggle elements.
mixedValuesUssClassNameUSS class name of Toggle elements that have mixed values
textUssClassNameUSS class name of Text elements in Toggle elements.
ussClassNameUSS class name for Toggle elements.

Constructors

Constructor

Description

Toggle()Creates a Toggle with no label.
Toggle(System.String)Creates a Toggle with a Label and a default manipulator.

Inheritance

Inherited Members