Users make choices and, often, these choices have one of two options (for example, sound on or off), or sometimes one of several possibilities (for example, difficulty level as easy/medium/hard). Unity UI Toggles allows users to turn options on and off; when combined with toggle groups, they restrict choices to one of the groups of items. In this recipe, we'll explore the basic Toggle and a script to respond to a change in values:
Figure 2.27 – Example showing the button's status changing in the Console window
Then, we'll extend the example to illustrate toggle groups and style these with round images to make them look more like traditional radio buttons. The preceding screenshot shows how the button's status changes are logged in the Console window when the scene is running.