Prototyping for AR – Vuforia Targeted Audio Tutorial

Prototyping for AR, Uncategorized
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.

Step 1

Follow this tutorial to use Vuforia in Unity in order 
to add a 3D object to an image target.

Step 2

In Unity, go to GameObject > Audio > Audio Source,
and add it to your Image Target as a child in the 

Step 3

Take the .mp3, .wav (or likewise) audio file and drag 
it into your Assets folder for the project in Unity

Step 4

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

Step 5

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

Step 6

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

Step 7

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!


Leave a Reply

Your email address will not be published. Required fields are marked *