The Vuforia component makes AR objects come to life in Unity, making it easy to apply 3D objects, images, video, audio and more onto targets. We learned how to use it to create augmented 3D objects on image targets, and now we’ll learn to trigger audio when that image (or other) target is recognised by the AR camera, adding sound effects to our augmented reality.
Follow this tutorial to use Vuforia in Unity in order to add a 3D object to an image target.
In Unity, go to GameObject > Audio > Audio Source, and add it to your Image Target as a child in the hierarchy.
Take the .mp3, .wav (or likewise) audio file and drag it into your Assets folder for the project in Unity
Drag the audio file into the Audio Clip section in the Inspector when you click the Audio Source
Make sure you uncheck the "Play on Awake" option, unless you want the audio to play every time the project starts
Stay in the Audio Source Inspector. In the 3D Sound Settings, tweak the Max Distance according to your project. The larger this is, the more likely that sound will be able to reach the audio listener of your ARCamera even when the distance from the Image Target is large
Create a C# Script. This will create your AudioSource. Here you can code how and what will trigger the audio in terms of number of targets, their order and hierarchies etc
The code should look something like this example, called ImageTargetPlayAudio, which implements the ITrackableEventHandler interface. Add it to your Image target.
Another example, for when multiple targets are added and require different sounds to be played according to the number of targets tracked
And you're done! Test the AR experience by hitting "Play" on your scene and use your target image to trigger the new sound you just added!