Making a fun slideshow using toggle buttons
Objective: Use toggles to move between slides.
To make use of toggles to change between slides is really easy. The first thin we will need to do is set up the scene. I have added a background with a banner on top. A preloaded image and text that will change when each toggle gets selected.
Next we will need to create a Toggle Group with three Toggles.
Each toggle needs to be made a part of the Toggle Group by adding the toggle group to the variable on each Toggle.
Now for the behavior, we will need to create a script. Before doing to much in the script, we need to make sure we are using UI Library. If you use Text Mesh Pro for the text, need to make sure you are using TMPro as shown in the picture below.
Next we need to grab the variables for the Toggles, sprites, the image holder that will swap in the sprites, and a text variable. Since we are using more than 1 toggle and sprite, these will be setup as an array.
All that is left is to create a public method for each toggle, 0–2. In these methods we will check to see if the respective toggle is on and we will add in the respective sprite from the array and set the text.
Back in Unity now is to create an Empty Object and add the script to it.
And to add the correct objects into each variable.
With the ButtonManager all set up, we need to go to each Toggle is drop in the ButtonManager to the On Value Changed and select the respective method.
With that we can toggle the slides.
Thank you for reading, have a wonderful day!