Game Development Reference
In-Depth Information
The
Toggle
specific options that are exposed (in the middle) give us a few capabilities:
•
Is On
: This determines the initial state of the
Toggle
, active/checked
•
Toggle Transition
: This controls how the toggle graphic enters and exits the
view, blinkered on/off or fades in/out (default)
There are only two options at present for the transition, I would have
liked to see more or at least a Mecanim hook-in here. Hopefully, it'll be
extended in future updates. If not, then you can always do it yourself.
•
Graphic
: This is the sprite to use for the check image (
not
the checkmark
GameObject as shown previously, which is the checkmark background),
this is the image that is turned on/off by the
Toggle
•
Group
: We'll cover this later, essentially, it allows for grouping of
Toggle
options together, only allowing a single item in a group to be checked at a time
So from the default setup that Unity gives you, all that is needed is a Toggle
graphic and you're done, but as Unity shows, you should really think beyond
that for a good UX.
Grouping toggles
As described earlier, in the
Toggle
control's properties, multiple toggles can be
grouped together under a single group. The net effect of a toggle group means that
only one
Toggle
within the group can be active (checked true) at a time. This is great
for those multiple choice situations where there can only be one right answer.
Groups can be placed anywhere on the scene, the best option however, is to create a
parent empty GameObject, add the
Toggle Group
component to it, and then place
each toggle that is part of the group as a child of this parent GameObject. For example:
1.
In a new scene, create a
Canvas
and add an empty
Empty
GameObject
as its
child. Name this new GameObject
Toggle Group
Parent
.
2.
Add the
Toggle Group
component to the
Toggle Group
Parent
GameObject.
3.
Add a
Toggle
control as a child of the
Toggle Group
Parent
GameObject.
4.
Select the
Toggle
and drag the
Toggle Group
Parent
to the
Group
property
of the
Toggle
component.
5.
Set the
Is On
property to
False
(unchecked).