Table of Contents

Playing audio in VCI

You can use AudioClip in VCI and control it from VCI script (Lua).
Here, we will explain the simplest way to use AudioClip.

Example audio

The recommended audio format is 44.1kHz 16bit WAVE.
There are some audio formats which may be playable on Unity but not playable after being exported as a VCI.

Embedding audio files in Unity

You may attach audio files (.wav, for instance) on any assets in Unity
be it a SubItem or a grandchildren object.

You can embed multiple audio files. However make sure that there are no two audio files with the same name, as audio files are distinguished by their file names.

VCI script

By using _ALL_PlayAudioFromName, you can play the embedded audio specified with its file name.
In this example, we embedded “clipname.wav”, so specify “clipname”.

main.lua
function onUse()
    vci.assets._ALL_PlayAudioFromName("clipname")
end

If you want to play a different audio file depending on the item being used, do as shown below.
The argument “item” in onUse(item) contains the name of the SubItem as a string.
By comparing the item in if statement, you can play different audio clips depending on its name.

main.lua
function onUse(item)
    if item == "Cube" then
        vci.assets._ALL_PlayAudioFromName("clipname")
    end
end