Enabling and customizing 3D sound effects
The default spatial setting for an AudioSource component is to be fully 2D. However, the Spatial Blend between 2D and 3D interpretation of a sound playing from a GameObject’s AudioSource is easily changed. Once the 3D location of an AudioSource is brought into the equation, many interesting audio effects are possible to enhance the player’s experience. In this recipe, we’ll move the spatial blend of an AudioSource fully to 3D, and customize the Volume Rolloff, which determines how a sound becomes quieter the further away it is located from the active AudioListener in a scene.
There are scenes where the best location of an AudioListener is not on a camera GameObject. This is often the case for third-person games, where the camera is behind/above the player’s character, and we want the player to hear the sounds that their animated character should be hearing (not where the observing camera is located). In this...