These are two simple and easy scripts that do exactly what they sound like: play sounds in a scene.
The difference between the two is that PlayBackgroundSound.cs is non-spatialized (like Scene Settings' Background Sound), and you'll always hear it at the same volume, regardless of your avatar/camera position.
Just add one or more of these scripts to an object or an existing audio emitter. The controls are as follows:
- Play longer sounds in sync for visitors to your scene. For example, you might have a piece of music that you want visitors to hear at precisely the same point as they join your scene, or perhaps voiceover dialog guiding them on what to do. It's useful for social and shared experiences!
- Play a sound that plays once when you enter a scene. For example, an introductory musical riff, or a brief spoken phrase you don't want repeated.
- Layer more sounds onto an existing audio emitter, if you want a "stack" of sounds playing in unison, without having to configure different emitters.
Sound - Click this dropdown to choose a sound from your inventory. A couple things to note:
- If you want this to be the only sound playing, under the corresponding emitter's Sound Settings, make sure to set Sound to (None).
- if you're using PlayObjectSound.cs with an object, the object needs to have an Audio emitter component present (which looks something like "Audio AUD0" in the Scene Objects list) to work.
- Volume Diff Percent - 0 means default loudness. This range appears different than the Level sliders found in non-scripted audio emitters, and ranges from -100 percent (silent) to 150.
- Play Once - Toggle this to On if you want a one-shot sound that plays once when a visitor enters a scene, and does not loop.
- Don't Sync - In case you have a use where you don't want sounds to sync for each visitor — meaning each new visitor hears the sound start at the beginning — set this to On.
Note that since these are scripts, their sounds currently can't be heard with Audio Preview — you need to build and visit your scene to hear them.
If you edit these scripts and build upon them, you need to attribute them as with other example scripts we provide. Have fun!