A SoundGroup 用於管理多次在多個 Sounds 上的音量和效果。音響群中的每一個聲音的音量都會由群組的 Volume 屬性調整,該屬性作為乘數,意味著一個 Sound 與音量 0.5 被分配給一個 SoundGroup 音量的 0.5 將有效音量 0.25 .
如果 SoundGroup 有任何 SoundEffects 作為子女,這些效果將適用於群組中的所有 Sounds 。
請注意,必須將 Sound 添加到 SoundGroup 以設置其 SoundGroup 屬性,而不是單純地將 Sound 傳送到 SoundGroup 。A Sound 只能屬於一個 SoundGroup 一次,雖然你可以在這裡 這裡 中巢穴化群組。
請參閱聲音群以獲得有關使用 SoundGroup 類別的進一步細節。
概要
屬性
Volume
音量倍率適用於 Sounds 屬於 SoundGroup 的值可從 0 到 10 範圍。
範例程式碼
This sample demonstrates how a SoundGroup can be used to change the volume of its associated Sounds and apply SoundEffects.
In this example a Sound is instanced in the Workspace and assigned to a new SoundGroup. The Sound is played and during playback the volume is changed via the SoundGroup and a SoundEffect is added.
SoundGroups
local SoundService = game:GetService("SoundService")
-- create a sound group
local soundGroup = Instance.new("SoundGroup")
soundGroup.Parent = SoundService
-- create a sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.PlaybackSpeed = 2
sound.SoundGroup = soundGroup
sound.Parent = workspace
-- play the sound
sound:Play()
task.wait(10)
-- change the volume
soundGroup.Volume = 0.1
task.wait(3)
-- return the volume
soundGroup.Volume = 0.5
task.wait(4)
-- add a sound effect
local reverb = Instance.new("ReverbSoundEffect")
reverb.Parent = soundGroup