Game Development Reference
In-Depth Information
Although the only ambient sound you have at the moment is the test sound in the SettingsMenu
scene, it should be able to retain its setting from previous adjustments. For that, you will have to use
the value set by the Level Manager as the slider's starting value.
In the SettingsGUI script's Start function, under the levelManager
assignment, add
2.
ambSliderValue = levelManager.ambientVolume; // set the volume to the stored value
diffSliderValue = levelManager.difficulty; // set the difficulty to the stored value
The Audio Source component was already updated from the LevelManager script, so you should be
ready to test.
3.
Save the script, and save the scene.
4.
Click Play from the StartMenu, and test the Settings menu by adjusting
the ambient sound, returning to the main menu and then going back to the
settings menu.
The volume setting and volume of the test Audio Component are retained between menus. The
Difficulty value is also retained.
As a final test, you can add some ambient sound effects to the garden scene. Unlike you did with the
visual elements of your scene, you will want to keep the audio separate from the rest of the garden
groups so it will always be active and able to be adjusted. Sound clips in Unity are 3D by default.
That means they automatically adjust their volume internally depending on how far away the main
camera (the camera with the Listener component) is from the object holding the Audio Source.
1.
Open the GardenLevel1 scene, and focus in on the Gnomatic Garden Defender.
2.
Create a new Empty GameObject, and name it Sound FX Birds .
3.
Move it to the center of the staging area, about 1 meter off of the ground.
4.
Add an Audio Source component to it.
5.
Load Birds as its Audio Clip, and check Loop.
6.
Assign the Ambient tag to it.
The falloff is spherical, but the character doesn't go into the corners, so you can adjust the falloff
curve so that the sound will stay pretty much “inside” the walled area. If you wanted full control, you
could add a box collider and have the Audio Source turn off and on using an OnTriggerEnter and
OnTriggerExit . Let's rely on the falloff to do all of the work this time. The enclosures are about
10 x 10 meters, so you can begin by setting the range.
1.
Set the Max Distance to 9 (Figure 10-43 ).
 
Search WWH ::




Custom Search