Last active
April 27, 2024 15:10
-
-
Save gamebox777/05579ed38fae764d808a94014bc7686f to your computer and use it in GitHub Desktop.
roblox:LocalScriptInput.lua プレイヤーの入力を受け取る部分
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- UserInputServiceを取得し、プレイヤーの入力を検出するためのサービスを利用 | |
local UserInputService = game:GetService("UserInputService") | |
-- ReplicatedStorageサービスを取得 | |
local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
-- ReplicatedStorageから「ModuleScriptBullet」という名前のModuleScriptを取得してロード | |
local fireBulletModule = require(ReplicatedStorage:WaitForChild("ModuleScriptBullet")) -- ModuleScript をロード | |
-- プレイヤーの入力が始まった際に呼び出される関数 | |
-- input: ユーザーからの入力イベント情報 | |
-- gameProcessedEvent: ゲームがすでにその入力を処理したかどうかのフラグ | |
local function onInputBegan(input, gameProcessedEvent) | |
-- ゲームが入力を既に処理している場合は何もしない | |
if gameProcessedEvent then return end | |
-- ユーザーがマウスの左ボタンをクリックしたか、Zキーを押した場合に実行 | |
if input.UserInputType == Enum.UserInputType.MouseButton1 or | |
input.KeyCode == Enum.KeyCode.Z then | |
-- 弾を発射する関数を呼び出す。現在のプレイヤーを引数として渡す | |
fireBulletModule.fireBullet(game.Players.LocalPlayer) | |
end | |
end | |
-- UserInputServiceのInputBeganイベントにonInputBegan関数を接続 | |
-- これにより、入力が始まるとonInputBegan関数が自動的に呼ばれる | |
UserInputService.InputBegan:Connect(onInputBegan) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment