O'Reilly logo

Microsoft HoloLens Developer’s Guide by Dennis Vroegop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Play the sound at the right time.

It is time to actually make the sound audible. We want the sound to play as soon as we add a guitar to our scene.

Well, to be honest, we have already done this. Since we have added an audio source to our prefab and set it to play on awake (and loop as well), it will play the moment you instantiate an object.

You will hear the sound immediately, but let's say for the sake of completeness that we want to control this from a script. Let's assume some other piece of code calls Play Sound, and we want our guitar to respond to that.

Let's change our application a bit so that it does just that.

First, we remove the Play on awake and Loop options in the AudioSource component; we want it to play when we ask it to, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required