When the sound is disabled, it is pointless to show the two volume sliders. Let's make sure they are only displayed if the sound parameter is checked. While we're at it, we'll make it look nice with a smooth fade in or fade out of the volume box!
The Tween
Alpha
component will help us modify the volume box's alpha smoothly. It works in a similar to other Tween
components we've seen so far.
Follow these steps to add the
Tween Alpha
component to our volume box:
Options
| Volume
GameObject.alpha
to search for components with that word.Ok, we've just added the Tween Alpha
component to our main menu window. Let's configure it to fade our volume box.
We need to configure this new Tween Alpha
component to make it fade our volume box in by tweening its alpha from 0 to 1. Then, we'll use the UIPlay Tween
component to play the tween in forward or reverse alternately at each click on the sound checkbox.
Select our Options
| Volume
GameObject and set its Tween
Alpha to these values:
In this configuration, our volume box's alpha will tween from 0 to 1 with an ease in and out effect, making it appear smoothly in 0.2 seconds. Let's see how we'll play it.
We need Tween Alpha
to be played when the sound Checkbox
is clicked:
Sound
| Checkbox
GameObject.play
with your keyboard to search for components with that word.OK, now, configure the newly added UIPlay Tween component, as follows:
Once configured, click Unity's play button. That's it! When you disable sound, the volume box fades out—when you enable it again, it fades back in.
3.137.217.95