Skip to content

Instantly share code, notes, and snippets.

@kapraran
Last active November 21, 2020 22:08
Show Gist options
  • Save kapraran/09a7630f4c03a5408746d0cb26b6e81b to your computer and use it in GitHub Desktop.
Save kapraran/09a7630f4c03a5408746d0cb26b6e81b to your computer and use it in GitHub Desktop.
Play SoundAsset Venice unleashed
local winMusic = nil
Events:Subscribe('Level:Loaded', function(levelName, gameMode)
local winSoundAsset = ResourceManager:SearchForDataContainer('Sound/Music/MP_Music/MP_Music_Winning_Patch_01')
if winSoundAsset ~= nil then
local entityPos = LinearTransform()
entityPos.trans = Vec3(0.0, 0.0, 0.0)
print(entityPos)
-- create data
local data = SoundEntityData()
data.transform = entityPos
data.sound = SoundAsset(winSoundAsset)
data.obstructionHandle = -1
data.playOnCreation = false
-- create entity
local entity = EntityManager:CreateEntity(data, entityPos)
-- spawn entity and keep reference
if entity ~= nil then
entity:Init(Realm.Realm_Client, true)
winMusic = SoundEntity(entity)
end
end
end)
Events:Subscribe('Player:UpdateInput', function()
if InputManager:WentKeyDown(InputDeviceKeys.IDK_F3) and winMusic ~= nil then
print('start')
winMusic:FireEvent('Start')
end
if InputManager:WentKeyDown(InputDeviceKeys.IDK_F4) and winMusic ~= nil then
print('stop')
winMusic:FireEvent('Stop')
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment