Toggles and radio buttons via Toggle Groups
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; and when combined with Toggle Groups, they restrict choices to one of the group of items. In this recipe, we'll first explore the basic Toggle, and a script to respond to a change in values. Then, we'll extend the example to illustrateToggle Groups, and styling these with round images to make them look more like traditional radio buttons.
The screenshot shows how the button's status changes are logged in the Console panel when the scene is running:

Getting ready
For this recipe, we have prepared the images that you'll need in a folder named UIDemoTextures
in the 02_09
folder.
How to do it...
To display an on/off UI Toggle to the user, follow these steps:
- Create a new Unity 2D project.
- In the Inspector...