PlayResourceSound

Definition

PlayResourceSound(string resourceDirectoryName_resourceFileName.ogg)

Description

This function plays the resource sound resourceDirectoryName_resourceFileName.ogg. If the loop state of resource sound is true, the sound will be played continuously, otherwise it will be played only once.
You can go to the Project Resources section through the Script Utility dialog (Tools > Script Editor > Tools > Script Utility), select the desired resource sound and hit “Copy Folder_File Name” button to copy the full name of the resource.

Parameters

resourceDirectoryName_resourceFileName.ogg
Specifies the full name of the resource sound.

Example 1

function OnTriggerEnter(otherActorName)
    --nil means main character controller
    if otherActorName == nil then
          LoadResource("Sounds""fire.ogg")
          PlayResourceSoundLoop("Sounds_fire.ogg")
          StopResourceSound("Sounds_fire.ogg")
    end
end

function OnTriggerStay(otherActorName)

end

function OnTriggerExit(otherActorName)
    --nil means main character controller
    if otherActorName == nil then
          PlayResourceSound("Sounds_fire.ogg")
    end
end
Assume that the above script is attached to a trigger named “trigger1”. Whenever the main character enters “trigger1”, we load “fire.ogg” resource sound located in “Sounds” directory–In order for LoadResource function to load the resource sound, you must first add “fire.ogg” sound resource through the Add Resource to Current Project dialog (File > Project > Add/Remove Resource to/from Current Project). Then we play this sound continuously using the PlayResourceSoundLoop function. This function sets the loop state of the resource “fire.ogg” to true. Then we stop the “fire.ogg” resource sound using the StopResourceSound function.
Since the loop state of the “fire.ogg” sound is set to true by the PlayResourceSoundLoop function when the main character enters the trigger “trigger1”, the PlayResourceSound function plays the “fire.ogg” sound continuously when the main character leaves the trigger “trigger1”.

Example 2

function OnTriggerEnter(otherActorName)
    --nil means main character controller
    if otherActorName == nil then
          LoadResource("Sounds""fire.ogg")
          PlayAllResourceSoundsOnce()
          StopAllResourceSounds()
    end
end

function OnTriggerStay(otherActorName)

end

function OnTriggerExit(otherActorName)
    --nil means main character controller
    if otherActorName == nil then
          PlayResourceSound("Sounds_fire.ogg")
    end
end
Assume that the above script is attached to a trigger named “trigger1”. Whenever the main character enters “trigger1”, we load “fire.ogg” resource sound located in “Sounds” directory. Then we play all the resource sounds once using the PlayAllResourceSoundsOnce function. This function sets the loop state of all resource sounds, including “fire.ogg”, which is located in the “Sounds” folder, to false. Then, using the StopAllResourceSounds function, we stop all resource sounds.
Since the loop state of the “fire.ogg” sound is set to false by the PlayAllResourceSoundsOnce function when the main character enters the trigger “trigger1”, the PlayResourceSound function plays the “fire.ogg” sound only once when the main character leaves the trigger “trigger1”.
adminPlayResourceSound