Unity, VRTK, Sound

smallarrows.GIF

Written by Alex Rickett

First, save at least one sound file into your Assets folder

Basically any file format is OK (wav, aiff, mp3, mp4, ogg)

Looping Sounds
Add an AudioSource to the object you want to make a sound.  (If you want it to be an ambient sound, like background music, you can create a new empty object and put it on that.)

Select the object to have sound in the
Hierarchy

Select Add Component->Audio Source
     Drag an drop a sound clip from the Assets tab onto the slot for AudioClip,

check the Loop box, if you would like it to place more than once.

Set the spatial blend as needed.
(set to 3D if you only want the sound to be quiet/silent when youre not close to the object.  Set to 2D if you want the sound to be audible all the time e.g. background music.  You can control this in greater detail  in 3D sound settings at the bottom of an AudioSource component).



VRTK_1aVRTK Sound when you touch an object

Your scene needs to be setup with the Headset and Controllers for VRTK

Select your object that will play sounds
Select Add Component search for VRTK_Interactable Object (If it does not have it.)
Select Add Component search for VRTK_InteractableObject_Unity Events

Select Add Component->Audio Source

     Drag an drop a sound clip from the Assets tab onto the slot for AudioClip,
     Uncheck the Play on Awake
.

(Next steps are very similar to playing an animation on touch)
Go to the VRTK_Interacable Object_Unity Events component

Click the + icon at the lower right of the On Touch (.....) box.
(If you are playing an animation already, this will create a second event slot).

Drag the object from the Hierarchy on to the newly created None (object) slot in the On Touch (...) in the Inspector.
VRTK_sound_event

Click the drop down menu reading No function and choose Audio Source -> Play()



If you do not hear your sound
PC: Select the audio icon in the lower right side of the screen.
VRTK_sound


Make sure the headset is active.
Headphones are connected to the headset
The sound output should be Vive