
上QQ阅读APP看书,第一时间看更新
How to do it...
To apply Audio Ducking to your soundtrack, follow these steps:
- Create a new Unity 3D project.
- Import the provided Unity package, Ducking, and the soundtrack.mp3 file into your project.
- Open the Ducking scene from Project panel folder, Ducking | _Scenes.
- Enter Run-Time by playing the scene and walk toward the semitransparent green wall in the tunnel, using the W, A, S, and D keys (by pressing Shift to run). You will hear the robotDucking speech audio clip play as the character collides with the green wall ("This your captain speaking ..."). Then stop the scene playing to return to Design-Time.
- Create a GameObject in the scene containing an AudioSource component linked to the soundtrack AudioClip. This can be done in a single step by dragging the music clip from the Project panel into either the Hierarchy or Scene panels.
- Ensure the GameObject soundtrack is selected in the Hierarchy. In the Inspector for the Audio Source component, make sure the Play On Awake option is checked, check the Loop option, and make sure its Spatial Blend is set to 2D (if necessary, see screenshot in the previous recipe for same action on the percussion GameObject).
- Play the scene again. The soundtrack music should be playing. Then stop the scene playing to return to Design-Time.
- In the Project panel, use the Create menu to add an Audio Mixer file. Rename this new file MainMixer.
- Double-click MainMixer to open the Audio Mixer panel.
- In the the Audio Mixer panel Groups section, highlight Master and click the + (plus) sign to add a child to the Master group. Name this child Music. Repeat these actions to add a second child of Master, named FX. Add a third child to the Master group, named Input:

- In the Audio Mixers view, add a new Mixer by clicking the + (plus) sign to add a new Mixer to the project. Name it MusicMixer. Drag it into the MainMixer (to become its child) and select the Music group as its Output:

- Repeat the previous step to add another child of MainMixer, named FxMixer, to the project, selecting the FX group as the output.
- Select MusicMixer. Select its Master group and add a child named Soundtrack:

- Select FxMixer and add a child named Bells.
- From the Hierarchy view, select the DialogueTrigger GameObject. In the Inspector, change the Output track to MainMixer | Input, for the Audio Source component:

- Select the Soundtrack GameObject. In the Inspector for the Audio Source component, change its Output track to MusicMixer | Soundtrack.
- From the Ducking | Prefabs folder in the Project panel, select the Signal prefab. In the Inspector, set its Audio Source component Output to FxMixer | Bells.
- Open the Audio Mixer window. Choose MainMixer, select the Music track controller, right-click on Attenuation, and using the context menu, add the Duck Volume effect:

- Select the Input track, right-click on Attenuation, and using the context menu, add Send.
- With the Input track still selected, go to the Inspector view and change the Receive setting in Send to Music\Duck Volume and its Send level to 0.00 db.
- Select the Music track. From the Inspector view, change the settings on the Duck Volume as follows: Threshold: -40.00 db, Ratio: 300.00%, Attack Time: 100.00 ms, Release Time: 200.00 ms:

- Test the scene again. Entering the trigger object will cause the soundtrack volume to drop considerably, recovering the original volume in two seconds.