學習
引擎類別
SoundService
無法建立
服務

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


範例程式碼
動態混響系統
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local SoundService = game:GetService("SoundService")
local localPlayer = Players.LocalPlayer
local reverbTags = {
["reverb_Cave"] = Enum.ReverbType.Cave,
}
-- 收集部件並按標籤分組
local parts = {}
for reverbTag, reverbType in pairs(reverbTags) do
for _, part in pairs(CollectionService:GetTagged(reverbTag)) do
parts[part] = reverbType
end
end
-- 函數檢查位置是否在部件的範圍內
local function positionInPart(part, position)
local extents = part.Size / 2
local offset = part.CFrame:PointToObjectSpace(position)
return offset.x < extents.x and offset.y < extents.y and offset.z < extents.z
end
local reverbType = SoundService.AmbientReverb
while true do
task.wait()
if not localPlayer then
return
end
local character = localPlayer.Character
-- 預設為無混響
local newReverbType = Enum.ReverbType.NoReverb
if character and character.PrimaryPart then
local position = character.PrimaryPart.Position
-- 遍歷所有索引的部件
for part, type in pairs(parts) do
-- 檢查角色是否在其中
if positionInPart(part, position) then
-- 如果是,則選擇該混響類型
newReverbType = type
break
end
end
end
-- 如果混響類型有變更則設置混響類型
if newReverbType ~= reverbType then
SoundService.AmbientReverb = newReverbType
reverbType = newReverbType
end
end

API 參考
屬性
AcousticSimulationEnabled
平行讀取
功能: Audio
SoundService.AcousticSimulationEnabled:boolean

AmbientReverb
平行讀取
功能: Audio
SoundService.AmbientReverb:Enum.ReverbType

CharacterSoundsUseNewApi
外掛程式安全性
平行讀取
功能: Audio
SoundService.CharacterSoundsUseNewApi:Enum.RolloutState

DefaultListenerLocation
外掛程式安全性
平行讀取
功能: Audio
SoundService.DefaultListenerLocation:Enum.ListenerLocation

DistanceFactor
平行讀取
功能: Audio
SoundService.DistanceFactor:number

DopplerScale
平行讀取
功能: Audio
SoundService.DopplerScale:number

ListenerCFrame
平行讀取
功能: Audio
SoundService.ListenerCFrame:CFrame

ListenerObject
平行讀取
功能: Audio
SoundService.ListenerObject:Instance

ListenerType
平行讀取
功能: Audio
SoundService.ListenerType:Enum.ListenerType

RespectFilteringEnabled
平行讀取
功能: Audio
SoundService.RespectFilteringEnabled:boolean

RolloffScale
平行讀取
功能: Audio
SoundService.RolloffScale:number

VolumetricAudio
無法建立指令碼
平行讀取
功能: Audio
SoundService.VolumetricAudio:Enum.VolumetricAudio

方法
GetListener
功能: Audio
SoundService:GetListener():Tuple
返回

GetMixerTime
功能: Audio
SoundService:GetMixerTime():number
返回

OpenAttenuationCurveEditor
外掛程式安全性
功能: Audio
SoundService:OpenAttenuationCurveEditor(selectedCurveObjects:Instances):()
參數
selectedCurveObjects:Instances
返回
()

OpenDirectionalCurveEditor
外掛程式安全性
功能: Audio
SoundService:OpenDirectionalCurveEditor(selectedCurveObjects:Instances):()
參數
selectedCurveObjects:Instances
返回
()

PlayLocalSound
功能: Audio
SoundService:PlayLocalSound(sound:Instance):()
參數
sound:Instance
返回
()

SetListener
功能: Audio
SoundService:SetListener(
listenerType:Enum.ListenerType, listener:Tuple
):()
參數
listenerType:Enum.ListenerType
listener:Tuple
返回
()

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。