Leçon 9

Table des matières

Audio Listener

For any game to enable sound, you need both an emitter and a listener. The emitter is the AkGameObj component handling the posted Events on the game object, whereas the listener refers to the game object with the AkAudioListener component.

In the above image, the emitter is the AkGameObj on the Ambient_River Event's game object. The listener is most often either the character you are controlling or the camera through which you are viewing. Decide thoughtfully on which is best for your situation. In the Wwise Adventure Game, the AkAudioListener component is added to the Main Camera. In the UniqueName's Hierarchy, you will find a Main Camera, a Directional Light, and a WwiseGlobal game object.

By default, the AkAudioListener script will automatically be added to the Main Camera, but let's disable that option and add the AkAudioListener to a new separate Player game object.

  1. In the Unity menu, go to Edit and select Wwise Settings…

    By default, the Wwise Unity Integration will add a listener to the Main Camera, as it is the most common use case. However, as some games require sounds to be based on where the Player is and not the Camera, like some 2D side-scrollers, let's manually add the listener to another game object.

  2. Under Asset Management, make sure that Automatically add listener to Main Camera is disabled and click OK.

    As the Untitled Scene was loaded once you opened Unity, the AkAudioListener will still be on the Main Camera even though the new scenes you'll make will not. As you have not changed anything in the Scene yet, a quick way to solve this is by creating a new Scene.

  3. In the Unity menu, go to File and select New Scene.

  4. In the Scene(s) Have Been Modified window, click Don't Save.

  5. In the Hierarchy, select the Main Camera.

    In the Inspector you will now see three components, with one of them being an Audio Listener component provided by Unity. This component is used with the Unity Audio Engine; however, as you are using Wwise, you should remove this component.

  6. Click the Component Context Menu (gear icon) and select Remove Component.

    Next, let's make a new game object, which we can use as the Player or character in the game, and add the AkAudioListener script to it. Ensure that you are viewing the Scene tab so you can see the new object appear in the Scene.

  7. In the Hierarchy, right-click in an empty space, go to 3D Object, and select Capsule.

    This capsule will act as the Player game object.

  8. In the Inspector, click Add Component, search for AkAudioListener and select it.

You have now added the Wwise Unity Integration Listener to the Capsule game object.

When you added the AkAudioListener, the AkGameObj script was also added. The AkGameObj script is used by the AkAudioListener, and so it was added automatically.


Cette page a-t-elle été utile ?