概要
方法
GetMotor(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor):Tuple |
IsMotorSupported(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor):boolean |
IsVibrationSupported(inputType: Enum.UserInputType):boolean |
SetMotor(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor,vibrationValues: Tuple):() |
API 參考
方法
GetMotor
參數
返回
IsMotorSupported
HapticService:IsMotorSupported(
參數
返回
IsVibrationSupported
參數
返回
SetMotor
HapticService:SetMotor(
):()
參數
返回
()
範例程式碼
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)