エンジンクラス
Mouse
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
Icon:ContentId |
イベント
KeyDown(key: string):RBXScriptSignal |
keyDown(key: string):RBXScriptSignal |
KeyUp(key: string):RBXScriptSignal |
APIリファレンス
プロパティ
Hit
コードサンプル
マウス.ヒットレーザー ビーム
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local beam = Instance.new("Beam")
beam.Segments = 1
beam.Width0 = 0.2
beam.Width1 = 0.2
beam.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam.FaceCamera = true
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1
beam.Parent = workspace.Terrain
attachment0.Parent = workspace.Terrain
attachment1.Parent = workspace.Terrain
local function onRenderStep()
local character = player.Character
if not character then
beam.Enabled = false
return
end
local head = character:FindFirstChild("Head")
if not head then
beam.Enabled = false
return
end
beam.Enabled = true
local origin = head.Position
local finish = mouse.Hit.Position
attachment0.Position = origin
attachment1.Position = finish
end
RunService.RenderStepped:Connect(onRenderStep)マウスの起点 vs マウスのヒット vs CurrentCameraの位置
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local mouse = player:GetMouse()
local camPos = camera.CFrame.Position
local function onButton1Down()
print("Mouse.Hit:", mouse.Hit.Position)
print("camPos:", camPos)
print("Mouse.Origin:", mouse.Origin.Position)
print("Magnitude:", (mouse.Origin.Position - camPos).Magnitude)
end
mouse.Button1Down:Connect(onButton1Down)hit
Icon
Mouse.Icon:ContentId
コードサンプル
ドラゴンマウスアイコン
local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=163023520"IconContent
コードサンプル
ドラゴンマウスアイコン
local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=163023520"Origin
コードサンプル
マウスの起点 vs マウスのヒット vs CurrentCameraの位置
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local mouse = player:GetMouse()
local camPos = camera.CFrame.Position
local function onButton1Down()
print("Mouse.Hit:", mouse.Hit.Position)
print("camPos:", camPos)
print("Mouse.Origin:", mouse.Origin.Position)
print("Magnitude:", (mouse.Origin.Position - camPos).Magnitude)
end
mouse.Button1Down:Connect(onButton1Down)Target
コードサンプル
カラーランダマイザーツール
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
local target = mouse.Target
if target then
print("クリックされた:", target:GetFullName())
if target:IsA("BasePart") then
target.BrickColor = BrickColor.random()
end
end
end)target
TargetSurface
コードサンプル
表面ランダマイザー
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local surfaceTypes = {
Enum.SurfaceType.Smooth,
Enum.SurfaceType.Glue,
Enum.SurfaceType.Weld,
Enum.SurfaceType.Studs,
Enum.SurfaceType.Inlet,
Enum.SurfaceType.Universal,
Enum.SurfaceType.Hinge,
Enum.SurfaceType.Motor,
}
local function onMouseClick()
-- マウスがパートを指していることを確認します
local target = mouse.Target
if not target then
return
end
local surfaceType = surfaceTypes[math.random(1, #surfaceTypes)]
local surface = mouse.TargetSurface
local propertyName = surface.Name .. "Surface"
mouse.Target[propertyName] = surfaceType
end
mouse.Button1Down:Connect(onMouseClick)ViewSizeX
コードサンプル
正規化されたマウス位置
local Players = game:GetService("Players")
-- 注意: このタスクを達成するには、Mouse オブジェクトの代わりに
-- ContextActionService または UserInputService を使用すべきです。
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- マウスの位置と画面サイズ用の Vector2 オブジェクトを構築します
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- 正規化された位置は、左上(上部バーのすぐ下)を (0, 0) に
-- マッピングし、右下を (1, 1) に、中心を (0.5, 0.5) にマッピングします。
-- これは、位置を総サイズで割ることによって計算されます。
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)ViewSizeY
コードサンプル
正規化されたマウス位置
local Players = game:GetService("Players")
-- 注意: このタスクを達成するには、Mouse オブジェクトの代わりに
-- ContextActionService または UserInputService を使用すべきです。
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- マウスの位置と画面サイズ用の Vector2 オブジェクトを構築します
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- 正規化された位置は、左上(上部バーのすぐ下)を (0, 0) に
-- マッピングし、右下を (1, 1) に、中心を (0.5, 0.5) にマッピングします。
-- これは、位置を総サイズで割ることによって計算されます。
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)X
コードサンプル
正規化されたマウス位置
local Players = game:GetService("Players")
-- 注意: このタスクを達成するには、Mouse オブジェクトの代わりに
-- ContextActionService または UserInputService を使用すべきです。
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- マウスの位置と画面サイズ用の Vector2 オブジェクトを構築します
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- 正規化された位置は、左上(上部バーのすぐ下)を (0, 0) に
-- マッピングし、右下を (1, 1) に、中心を (0.5, 0.5) にマッピングします。
-- これは、位置を総サイズで割ることによって計算されます。
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)Y
コードサンプル
正規化されたマウス位置
local Players = game:GetService("Players")
-- 注意: このタスクを達成するには、Mouse オブジェクトの代わりに
-- ContextActionService または UserInputService を使用すべきです。
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- マウスの位置と画面サイズ用の Vector2 オブジェクトを構築します
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- 正規化された位置は、左上(上部バーのすぐ下)を (0, 0) に
-- マッピングし、右下を (1, 1) に、中心を (0.5, 0.5) にマッピングします。
-- これは、位置を総サイズで割ることによって計算されます。
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)イベント
Idle
コードサンプル
マウス.Idle
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local events = {
"Button1Down",
"Button1Up",
"Button2Down",
"Button2Up",
"Idle",
"Move",
"WheelBackward",
"WheelForward",
"KeyDown",
"KeyUp",
}
local currentEvent
local frame = 0
local function processInput()
frame = frame + 1
print("フレーム", frame, "- マウスイベントが", currentEvent, "に渡されました")
end
for _, event in pairs(events) do
mouse[event]:Connect(function()
currentEvent = event
end)
end
RunService:BindToRenderStep("ProcessInput", Enum.RenderPriority.Input.Value, processInput)KeyDown
keyDown
KeyUp
Move
コードサンプル
マウスでパーツを移動する
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local point
local down
local function selectPart()
if mouse.Target and not mouse.Target.Locked then
point = mouse.Target
mouse.TargetFilter = point
down = true
end
end
local function movePart()
if down and point then
local posX, posY, posZ = mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z
point.Position = Vector3.new(posX, posY, posZ)
end
end
local function deselectPart()
down = false
point = nil
mouse.TargetFilter = nil
end
mouse.Button1Down:Connect(selectPart)
mouse.Button1Up:Connect(deselectPart)
mouse.Move:Connect(movePart)WheelBackward
コードサンプル
マウス.WheelBackward
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelBackward()
print("ホイールが後方に移動しました!")
end
mouse.WheelBackward:Connect(onWheelBackward)WheelForward
コードサンプル
マウス.WheelForward
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelForward()
print("Wheel went forward!")
end
mouse.WheelForward:Connect(onWheelForward)