玩家滑鼠與 Mouse 對象相同,可以使用 Tool.Equipped 來存取。它可以從 LocalScripts 使用本地玩家的 1> Class.Player:GetMouse()1> 方
PlayerMouse 和 Mouse 對象唯一的區別是,PlayerMouse 可以使用 Player:GetMouse() 方法獲得。
大多數情況下,建議開發人員使用新的 UserInputService 。 但是玩家滑鼠和滑鼠對象仍然為數種原因提供支持。 請參閱 輸入和鏡頭 以獲得更多有關自訂輸入的資體驗。
範例程式碼
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
print("mouse screen position: ", mouse.X, mouse.Y)
end
mouse.Move:Connect(onMouseMove)
概要
屬性
屬性 繼承自 MouseThe CFrame of the mouse's position in 3D space.
The content ID of the image used as the Mouse icon.
A CFrame positioned at the Workspace.CurrentCamera and oriented toward the mouse's 3D position.
The object in 3D space the mouse is pointing to.
Determines an object (and its descendants) to be ignored when determining Mouse.Hit and Mouse.Target.
Indicates the Enum.NormalId of the BasePart surface at which the mouse is pointing.
A Ray directed towards the mouse's world position, originating from the Workspace.CurrentCamera world position.
Describes the width of the game window in pixels.
Describes the height of the game window in pixels.
Describes the X (horizontal) component of the mouse's position on the screen.
Describes the Y (vertical) component of the mouse's screen position.
活動
活動 繼承自 MouseFired when the left mouse button is pressed.
Fires when the left mouse button is released.
Fires when the right mouse button is pressed.
Fired when the right mouse button is released.
Fired during every heartbeat that the mouse isn't being passed to another mouse event.
Fired when the mouse is moved.
Fires when the mouse wheel is scrolled backwards.
Fires when the mouse wheel is scrolled forwards.