Creating a toggle group

In this recipe, you will learn how to create a toggle group. Often in menus, there is an opportunity to choose between different options, but the player can choose only one of them. A toggle group allows users to select just one of its toggles. To achieve this, we will use the Toggle (Script) component along with the Toggle Group (Script) component.

How to do it...

  1. First of all, we need to create a panel in which our toggle elements will be placed. To do this, right-click on the Hierarchy panel and then on UI | Panel. Rename it to Toggle Group. Of course, it is possible to resize and place the panel as we wish.
  2. The next step is to add a Toggle Group (Script) component to our Toggle Group panel. To do so, click on Add Component ...

Get Unity UI Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.