Removing redundant AudioListener components
There are times when we may end up with more than one AudioListener in a scene, so need to remove or deactivate one to avoid problems. We’ll learn how to do so in this recipe.
Getting ready
You can find several Pacman game sound clips inside the 04_02
folder.
How to do it...
To remove AudioListener components, perform the following steps:
- Create a new Unity 2D project. There is a single sample scene, containing a
Main Camera
GameObject that has an Audio Listener component. - Import the sound clip files.
- Select the
Main Camera
GameObject in the Hierarchy, and then from the Project panel, drag thePacman Opening Song
audio clip into the Inspector. - Save and play the scene. You should hear the Pacman song play once as soon as the scene begins.
- Now, add a second camera to the scene, choosing GameObject | Camera. Rename this GameObject
Camera2
. - Save and play the scene. You should hear...