Adding basic 3D spatialization
In this section, we'll dive deeper into that Spatial Blend property we looked at earlier and create sound that has a discrete location in the level. We'll start by adding a few 3D sounds to our interactive walls: one to play when it's activated, and another to play when it's destroyed.
Find the audio files included with this chapter called WallActivated.wav
and WallDestroyed.wav
and drag them into your Audio
folder:
Open your DynamicWall
script and add two variables to store references to these sounds, as well as one for the Audio Source component:
public class DynamicWall : MonoBehaviour { ... [SerializeField] private AudioClip wallActivatedClip; [SerializeField] private AudioClip wallDestroyedClip; private AudioSource audioSource; ... }
We'll have to add an Audio Source component to the wall prefab before we can get a reference to it, so find an instance of DynamicWallBase to the scene and click...