VRのコントローラーのON/OFFの検知は、UserInputService の InputBegan と InputEnded のイベントを使用します。
InputBegan はボタンが押されたときに発生するイベントで、InputEnded はボタンが離されたときに発生するイベントです。
StarterPlayer の StarterPlayerScripts に LocalScript を追加し、以下のプログラムを入力します。

local UserInputService = game:GetService("UserInputService")
local VRService = game:GetService("VRService")

-- ボタンが押されたときに呼ばれる
local function onInputBegan(input, processed)
    if input.KeyCode == Enum.KeyCode.〇〇〇〇 then
        -- ボタンが押された時の処理
    end
end

-- ボタンが離されたときに呼ばれる
local function onInputEnded(input, processed)
    if input.KeyCode == Enum.KeyCode.〇〇〇〇 then
        -- ボタンが離された時の処理
    end
end

UserInputService.InputBegan:Connect(onInputBegan)
UserInputService.InputEnded:Connect(onInputEnded)

Enum.KeyCode.〇〇〇〇 は以下のボタンに対応します。(例:Enum.KeyCode.ButtonA)

アナログのボタン

ButtonL1、ButtonL2、ButtonR1、ButtonR2は、アナログ的に押し具合を取得することができます。その場合は、InputChanged イベントを使用します。input の Position は Vector3型になっていますが、その Z に0から1の数字が入ります。1がMAXで押されているということになります。

UserInputService.InputChanged:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.〇〇〇〇 then
        local analogValue = input.Position.Z -- アナログ値の取得0~1)
    end
end)

By schilverberch

ROBLOXでゲームを作ろう! 一緒にプログラミングを学びましょう。

コメントを残す