玩家鼠标与使用 获得的对象相同行为。它可以使用本地玩家的 LocalScripts 方法从 Player:GetMouse() 访问。PlayerMouse 和 Mouse 都是遗产 API,被 UserInputService 取代。
玩家鼠标和 Mouse 对象之间的唯一差异是玩家鼠标可以使用 Player:GetMouse() 方法获得。
在大多数情况下,开发人员建议使用新的 UserInputService 。但是,玩家鼠标和鼠标对象仍然支持多种原因。请参阅输入和相机获取有关体验中自定义输入的更多信息。
代码示例
This code sample includes a simple example of how the local player's PlayerMouse can be retrieved using the Player:GetMouse() function in a LocalScript. This code should be placed in a LocalScript in StarterPlayerScripts.
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)
概要
属性
继承自Mouse的属性属性
鼠标位置在 3D 空间的 CFrame。
用作Mouse图标的图像内容ID。
位于 并面向鼠标 3D 位置的 A。
在 3D 空间中指向的对象 mouse 。
决定在确定 Mouse.Hit 和 Mouse.Target 时忽略对象 (和其子孙)。
指示鼠标指向的 Enum.NormalId 表面上的 BasePart 。
一个 Ray 指向鼠标世界位置,起源于 Workspace.CurrentCamera 世界位置。
描述游戏窗口的宽度以像素为单位。
描述游戏窗口的高度以像素计。
描述鼠标位置在屏幕上的 X(横向)组件。
描述鼠标屏幕位置的 Y(垂直)组件。
活动
继承自Mouse的活动活动
当左鼠标按钮被按下时发火。
当左鼠标按钮释放时发火。
当按下右键时发生火焰。
当右键按钮释放时发射。
在鼠标不被传递到另一个鼠标事件期间,每次心跳时发射。
当鼠标移动时发射。
当鼠标轮向后滚动时发生火焰。
当鼠标轮滚动向前时发射。