學習
引擎類別
HapticService
已棄用
無法建立
服務
未複製

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


概要
繼承成員

API 參考
方法
GetMotor
功能: Input
HapticService:GetMotor(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor
參數
vibrationMotor:Enum.VibrationMotor
返回

IsMotorSupported
功能: Input
HapticService:IsMotorSupported(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor
參數
vibrationMotor:Enum.VibrationMotor
返回

IsVibrationSupported
功能: Input
HapticService:IsVibrationSupported(inputType:Enum.UserInputType):boolean
參數
返回

SetMotor
功能: Input
HapticService:SetMotor(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor, vibrationValues:Tuple
):()
參數
vibrationMotor:Enum.VibrationMotor
vibrationValues:Tuple
返回
()
範例程式碼
HapticService:SetMotor()
local UserInputService = game:GetService("UserInputService")
local HapticService\ = game:GetService("HapticService")
local cachedInputs = {}
local keyToVibration\ = {
\t[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
\t[Enum.KeyCode.ButtonR2]\ = Enum.VibrationMotor.Large,
}\n
local function onInputChanged(property)\n\tif property == "Position" then\n\t\tHapticService:SetMotor(inputType, vibrationMotor,\n\ input.Position.Z)\n\tend\nend\n
local function onInputBegan(input)\n\tif not\ cachedInputs[input] then\n\t\tlocal inputType = input.UserInputType\n\t\tif\n\ inputType.Name:find("Gamepad") then\n\t\t\tlocal vibrationMotor = keyToVibration[input.KeyCode]\n\t\t\tif vibrationMotor then\n\t\t\t\t-- 手動監控這個輸入以準確更新震動馬達\n\t\t\t\tcachedInputs[input] = input.Changed:Connect(onInputChanged)\n\t\t\tend\n\t\tend\n\tend\nend\n
UserInputService.InputBegan:Connect(onInputBegan)

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