Game Development Reference
In-Depth Information
Audio clips are imported into Unity as 3D sounds by default. With the Volume Rolloff set to
Logarithmic Rolloff, the clip will be pretty much gone at 50 meters. (See the bottom of the graph in
Figure 6-7 .) It should be audible in this small scene, but if not, you can increase the Max Distance,
adjust the curve, or change the Volume Rolloff to Linear Rolloff.
2.
Just to make sure you can hear the clip, change the Volume Rolloff to
Linear Rolloff.
3.
Uncheck the “Play on Awake” option.
4.
Drag the Sound FX folder into the Project view from the Chapter 6 Assets folder.
5.
Load the Chest Open audio clip into the Audio Clip parameter.
Unity converts most sound clips into the .ogg format for desktop and web deployments. Ogg files
are an open source mpeg-like format. For mobile, Unity generally uses mpeg format. The mpeg
license is covered for mobile by the hardware manufacturers and is hardware accelerated.
Feel free to add more sound effects to the project. Many are free to use but cannot be redistributed,
so the project only comes with a few. You must have one Audio Listener in the scene to be able to
play audio clips. Remember to remove extra Audio Listeners whenever you add Cameras to your
scenes. You can click on the audio clips in the Project view to hear the clips play.
Next you will add a few lines of code to include your sound effect. In this case, you can use the
same sound for open and close.
In the SensorDoors script, beneath the animation.Play() code in each of the
OnTrigger... functions, add the following:
6.
audio.Play(); // play the clip loaded in the audio component
7.
Save the script, and click Play.
The bench heads through the gateway accompanied by the new sound effect. With the animated
gates working well, you will want to create a prefab to go with the rest of your modular garden
pieces.
8.
Drag the GardenGates object into the Prefabs, Structures folder.
9.
Deactivate the bench.
Mecanim
With Unity's Mecanim animation system, character animation is the main focus. There are three
main parts of Mecanim: The importer, where you can manipulate the animation clips to alter or refine
the raw imported animation, the Rig section, where you can 'map', or retarget animation from one
character to another as long as they are both humanoid, and the Animator Controller, Mecanim's
state engine, where animation states are set up to blend between each other according to various
criteria. Additionally, Mecanim's masking system lets you isolate body parts and blend animations
between multiple sources for complex combinations on demand. If you are a Pro user, you can even
set up IK (inverse kinematics) to override baked animations so the characters can interact with other
objects in the scene dynamically.
 
Search WWH ::




Custom Search