Mouse

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음

마우스 는 더 넓은 범위를 다루고, 더 많은 기능을 포함하며, 크로스 플랫폼 패턴을 더 잘 지원하는 와 에 의해 대체되었습니다.광범위하게 사용되기 때문에 지원되지만, 이러한 대안을 사용해야 강력히 고려해야 합니다.

마우스 개체는 주로 버튼과 레이캐스팅에 사용되는 다양한 API를 보유하고 있습니다.그것은 Player:GetMouse() 호출된 Players.LocalPlayer 에서 액세스할 수 있습니다 LocalScript.또한 Tool.Equipped 이벤트에 의해 전달됩니다.


-- 로컬 스크립트에서:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
-- 마우스 아이콘 설정
mouse.Icon = "rbxasset://SystemCursors/Wait"

참고:

  • 이 개체는 포인터 이동을 제어하거나 제한하지 않습니다. 이를 위해 UserInputService.MouseBehaviorUserInputService.MouseDeltaSensitivity 를 참조하십시오.

  • 두 함수가 동일한 입력 이벤트에 연결되어 있는 경우, 와 같이, 두 함수 모두 이벤트가 발생할 때 실행됩니다.이벤트가 이 동작을 지원하지 않기 때문에 입력 침하/전달 개념이 없습니다.그러나, ContextActionService 는 이 동작을 통해 BindAction 을 가집니다.

  • 모든 플랫폼에서 마우스를 사용할 수 없지만, 마우스는 일반적으로 마우스 또는 포인터 하드웨어가 없는 모바일(터치) 및 콘솔(게임패드)에서 여전히 작동합니다.명시적 크로스 플랫폼 동작은 UserInputServiceContextActionService를 사용하십시오.

    경험에서 입력을 사용자 정의하는 방법에 대한 자세한 내용은 입력 및 카메라를 참조하십시오.

요약

속성

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    3D 공간에서 마우스 위치의 CFrame입니다.

  • Icon:ContentId
    병렬 읽기

    Mouse 아이콘으로 사용된 이미지의 콘텐츠 ID.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    A 는 마우스의 3D 위치에 배치되고 마우스 방향으로 향합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    3D 공간의 개체 mouse 가 가리키는 것.

  • 병렬 읽기

    Mouse.HitMouse.Target를 결정할 때 무시할 개체(그 하위 개체)를 결정합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    마우스가 가리키는 표면의 부분을 나타냅니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    마우스의 세계 위치를 향하여 출발하는 세계 위치에서 발생하는 A.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    게임 창의 너비를 픽셀로 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    픽셀로 된 게임 창의 높이를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    화면에서 마우스 위치의 X(가로) 구성 요소를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    마우스의 화면 위치의 Y(가로) 구성 요소를 설명합니다.

이벤트

속성

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 3D 공간에서 마우스 위치의 CFrame를 나타냅니다. Mouse.TargetFilter와 그 후손은 무시됩니다.

개발자는 다음과 같이 히트의 위치를 가져올 수 있습니다.


local position = mouse.Hit.Position

히트는 종종 Tools에 의해 셋째 인격의 마우스에 무기를 발사하기 위해 사용됩니다.

마우스가 가리키고 있는 것을 찾는 개발자는 을 사용해야 합니다.

Mouse.Hit는 어떻게 계산됩니까?

히트 C프레임의 위치는 마우스의 내부 Ray(확장된 버전의 Mouse.UnitRay)와 3D 공간의 개체(예: 부품) 사이의 교차점으로 계산됩니다.

히트 C프레임의 방향은 Mouse.UnitRay의 방향과 일치합니다.


local unitRayDirection = mouse.UnitRay.Direction
local mouseHitDirection = mouse.Hit.lookVector
-- unitRayDirection ≈ mouseHitDirection
-- the vectors are approximately equal

참고, 의 롤은 히트의 방향을 계산할 때 사용되지 않습니다.

마우스의 내부 광선은 1,000스터드에 걸쳐 확장됩니다.마우스가 3D 공간에서 개체에 가리키지 않으면(예를 들어 하늘을 가리키는 경우) 이 속성은 Workspace.CurrentCamera 에서 1,000스터드 떨어져 있습니다.

코드 샘플

The code in this sample, when placed inside a LocalScript within StarterPlayerScripts will draw a red laser beam between the character's head and Mouse.Hit at all times.

Note, this beam will pass directly through obstructions in third person as the Mouse's raycasting is done from the Workspace.CurrentCamera not the head.

Mouse.Hit Laser Beam

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)

The code below visualizes the difference between Mouse.Hit and Mouse.Origin. In order to do this, the code uses the Vector3 positions of the hit and origin CFrame values using .p.

The difference is that the origin is "where the mouse came from" (its origin) and the hit is the position where the mouse hits (is when the player presses their mouse).

This example also visualizes that the mouse origin is very similar to the position of the CurrentCamera by printing the magnitude (distance) between the two positions.

Mouse Origin vs Mouse Hit vs CurrentCamera Position

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)

Icon

ContentId
병렬 읽기

아이콘 은 포인터로 사용되는 이미지를 결정하는 속성입니다.비어 있으면 기본 화살표가 사용됩니다.커서가 GuiButton 놓일 때, 이 속성은 일시적으로 무시됩니다.

커서를 완전히 숨기려면 투명한 이미지를 사용하지 마십시오 – 대신, UserInputService.MouseIconEnabled를 false로 설정하십시오.

경험에서 사용자 마우스 아이콘을 가져오거나 설정하려면 UserInputService.MouseIcon를 사용해야 합니다.Mouse.Icon 플러그인의 새 API가 릴리스되면 마우스 커서 설정을 위한 새로운 API가 사용되지 않게 됩니다.

커서 디자인

다음 가이드라인은 자신의 마우스 커서를 만들 때 유용할 수 있습니다:

  • 사용된 이미지의 차원은 커서의 크기를 결정합니다.
  • 이미지의 중앙 은 마우스 입력이 발생하는 곳입니다. * 기본 마우스 이미지는 64x64픽셀이며, 마우스가 17x24픽셀의 공간을 차지합니다.
시스템 커서

에서 검색된 아이콘을 사용할 때, 손, 화살표, I-빔과 같이 시스템의 기본 커서와 유사한 아이콘을 사용할 수 있습니다.When using a retrieved from , you can use the following icons similar to your system's default cursors, such as hands, arrows, I-beams, etc.GUI 이벤트(MouseEnter, MouseLeave, MouseButton1Down)와 함께 사용하여 특정 GUI 구성 요소와 상호작용할 때 일관된 Studio 경험을 제공할 수 있습니다.이들은 스튜디오 플러그인에만 작동하며, 다른 Mouse 개체에는 작동하지 않습니다.


<th>자산</th>
<th>제안된 사용</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Pointer.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Arrow</code></td><td>기본 클릭 및 선택.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-PointingHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/PointingHand</code></td><td>활성 링크/버튼 위로 마우스를 이동합니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-OpenHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/OpenHand</code></td><td>드래그 가능한 아이템가리키는 중.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-GrabbingHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/ClosedHand</code></td><td>아이템을 드래그합니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-IBeam.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/IBeam</code></td><td>텍스트 필드에서 호버링합니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNS.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNS</code></td><td>수직 크기 조정 핸들을 가리키는 중입니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeEW.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeEW</code></td><td>수평 크기 조정 핸들을 가리키는 중입니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNESW.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNESW</code></td><td>모서리 크기 조정 핸들을 가리키는 중.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNWSE.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNWSE</code></td><td>모서리 크기 조정 핸들을 가리키는 중.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeAll.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeAll</code></td><td>다방향 크기 조정 핸들을 가리키는 중입니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeSplitV.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SplitNS</code></td><td>수직 "분할" 핸들을 가리키는 중입니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeSplitH.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SplitEW</code></td><td>수평 "분할" 핸들을 가리키는 중입니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Forbidden.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Forbidden</code></td><td>잠긴/금지된 아이템가리키는 중.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Wait.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Wait</code></td><td>작업이 진행 중임을 나타냅니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Busy.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Busy</code></td><td>시스템이 바쁜 것을 나타냅니다.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Crosshair.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Cross</code></td><td>핀포인트 선택 영역을 가리키는 중.</td>
</tr>
</tbody>
보기*
\* 이러한 모양은 대략적인 것입니다 — 실제 모양은 운영 체제에 따라 달라집니다.

코드 샘플

This example changes the Players.LocalPlayer mouse icon to look like a dragon image.

Dragon Mouse Icon

local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=163023520"

Origin

읽기 전용
복제되지 않음
병렬 읽기

원본 속성 Mouse는 마우스가 시작된 위치를 나타내는 CFrame입니다.그것은 Workspace.CurrentCamera 에 위치하고 마우스의 3D 위치에 향하고 있습니다.

Mouse.UnitRay는 원본과 동일한 위치에서 시작하고 동일한 방향으로 스터드가 확장됩니다.


local unitRay = mouse.UnitRay
local origin = mouse.Origin
-- unitRay.Direction = 원점.p
-- unitRay.Direction ≈ origin.lookVector

3D 공간에서 Mouse의 위치에 대해서는 Mouse.Hit를 참조하십시오.

코드 샘플

The code below visualizes the difference between Mouse.Hit and Mouse.Origin. In order to do this, the code uses the Vector3 positions of the hit and origin CFrame values using .p.

The difference is that the origin is "where the mouse came from" (its origin) and the hit is the position where the mouse hits (is when the player presses their mouse).

This example also visualizes that the mouse origin is very similar to the position of the CurrentCamera by printing the magnitude (distance) between the two positions.

Mouse Origin vs Mouse Hit vs CurrentCamera Position

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

읽기 전용
복제되지 않음
병렬 읽기

3D 공간의 개체 mouse 가 가리키는 것.

참고:

  • Mouse.TargetFilter가 설정되어 있으면 대상 필터와 그 하위 필터가 무시됩니다.
  • 마우스가 하늘을 가리키고 있지 않을 때, 예를 들어 마우스가 가리키고 있을 때 BasePart, 대상은 nil가 됩니다.
  • 3D 공간에서 마우스 위치를 찾는 개발자는 Mouse.Hit를 사용해야 합니다.

코드 샘플

The following code sample, when placed in StarterPlayerScripts will create a tool in the player's backpack that, once equipped, will change the BasePart.BrickColor of every BasePart the player clicks on.

Color Randomizer Tool

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local backpack = localPlayer:WaitForChild("Backpack")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false
tool.Parent = backpack
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
mouse.Target.BrickColor = BrickColor.random()
end
end)
end)

TargetFilter

병렬 읽기

이 속성은 마우스가 Mouse.HitMouse.Target를 계산할 때 무시할 개체를 결정합니다.개체의 후손도 무시되므로 이 속성이 설정된 개체의 후손이면 여러 개체를 무시할 수 있습니다.이 속성은 Mouse.Hit 또는 Mouse.Target에 영향을 주지 않는 특수 효과나 장식이 포함된 모델을 필터링할 때 유용합니다.

이 속성은 예를 들어 Instance 또는 nil 에 설정할 수 있습니다.


local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
mouse.TargetFilter = Workspace.Model

마우스에 의해 자동으로 무시되는 CharacterPlayers.LocalPlayer 가 참고하십시오.

TargetSurface

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 마우스가 가리키는 표면의 Enum.NormalId 에 있는 BasePart 를 나타냅니다.이 속성은 마우스의 세계 위치(Mouse.Hit)와 마우스가 가리키는 부분(Mouse.Target)에서 파생됩니다.

마우스가 부품에 가리키지 않을 때, 예를 들어 마우스가 하늘을 가리키고 있을 때 이 속성은 의미가 없습니다.현재 이 속성은 이러한 상황에서 '오른쪽'으로 설정됩니다.이 속성을 사용하기 전에 마우스의 대상이 아닌지 확인하십시오(nil).


local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
-- 마우스가 가리키는 부분이 있는지 확인하십시오
if mouse.Target then
print("The mouse is pointing to the " .. mouse.TargetSurface.Name .. " side of " .. mouse.Target.Name)
else
print("The mouse is not pointing at anything.")
end

코드 샘플

The code in this sample, when placed in a LocalScript inside StarterPlayerScripts will set the surface of any BasePart clicked on to a random surface.

Surface Randomizer

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()
-- make sure the mouse is pointing at a part
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)

UnitRay

읽기 전용
복제되지 않음
병렬 읽기

UnitRay 속성은 3D 공간에서 마우스의 위치를 향하는 Ray 방향입니다(설명됨 Mouse.Hit ).그것은 CFrameWorkspace.CurrentCamera 에서 비롯됩니다.모든 유닛 레이와 마찬가지로, 거리는 1입니다.


local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
print(mouse.UnitRay.Direction.Magnitude) -- Always 1

ViewSizeX

읽기 전용
복제되지 않음
병렬 읽기

ViewSizeX 속성은 게임 창의 너비 구성 요소 크기를 픽셀로 설명합니다.

코드 샘플

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)

ViewSizeY

읽기 전용
복제되지 않음
병렬 읽기

ViewSizeY 속성은 게임 창의 크기를 픽셀로 나타내는 세로 구성 요소를 설명합니다. 이 길이에는 상단 표시줄에 사용되는 공간이 포함됩니다.

코드 샘플

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)
읽기 전용
복제되지 않음
병렬 읽기

화면에서 마우스 위치의 변경을 감지할 때, 이 및 관련 속성을 사용하는 대신 또는 또는 를 사용하는 것이 좋습니다. 이는 모두 마우스의 위치를 (a >) 를 사용하여 설명하며, 이 및 관련 속성을 사용하지 않습니다.

X 속성은 화면에서 마우스 위치의 가로 구성 요소를 설명합니다.위치는 상단 모서리 아래에서 왼쪽 상단 픽셀로 측정됩니다. The position is measured in pixels relative to the top left corner, under the topbar.이 속성은 Mouse.Y와 함께 사용하여 마우스의 위치를 나타내는 Vector2를 생성할 수 있습니다.


local position = Vector2.new(mouse.X, mouse.Y)

이 속성은 Changed 또는 GetPropertyChangedSignal에서 반환된 신호를 발사하지 않습니다. 대신 Mouse.Move 이벤트를 사용하십시오.

코드 샘플

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)
읽기 전용
복제되지 않음
병렬 읽기

화면에서 마우스 위치의 변경을 감지할 때, 이 및 관련 속성을 사용하는 대신 또는 또는 를 사용하는 것이 좋습니다. 이는 모두 마우스의 위치를 (a >) 를 사용하여 설명하며, 이 및 관련 속성을 사용하지 않습니다.

Y 속성은 화면에서 마우스 위치의 세로 구성 요소를 설명합니다.위치는 상단 모서리 아래에서 왼쪽 상단 픽셀로 측정됩니다. The position is measured in pixels relative to the top left corner, under the topbar.이 속성은 Mouse.X와 함께 사용하여 마우스의 위치를 나타내는 Vector2를 생성할 수 있습니다.


local position = Vector2.new(mouse.X, mouse.Y)

이 속성은 Changed 또는 GetPropertyChangedSignal에서 반환된 신호를 발사하지 않습니다. 대신 Mouse.Move 이벤트를 사용하십시오.

코드 샘플

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)

메서드

이벤트

Button1Down

이 이벤트는 플레이어가 왼쪽 마우스 버튼을 누를 때 발생합니다.이것은 Tool에서 액세스할 수 있으며, 예를 들어, LocalScript에 배치되면 왼쪽 마우스 버튼이 누르질 때마다 아래의 코드가 Button1Down 인쇄된다.


local tool = script.Parent -- 이것이 도구 개체인지 확인하십시오
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
print("Button1Down")
end)
end)

세계 공간에서 마우스의 위치와 포인트 여부를 및 속성을 사용하여 찾을 수 있습니다.


Button1Up

이 이벤트는 플레이어가 왼쪽 마우스 버튼을 릴리스할 때 발생합니다.이것은 Tool에서 액세스할 수 있으며, 예를 들어, LocalScript에 배치되면 아래 코드는 왼쪽 마우스 버튼이 릴리스될 때마다 Button1Up을 인쇄합니다


local tool = script.Parent -- 이것이 도구 개체인지 확인하십시오
tool.Equipped:Connect(function(mouse)
mouse.Button1Up:Connect(function()
print("Button1Up")
end)
end)

세계 공간에서 마우스의 위치와 포인트 여부를 및 속성을 사용하여 찾을 수 있습니다.


Button2Down

이 이벤트는 플레이어가 오른쪽 마우스 버튼을 누를 때 발생합니다.이것은 Tool에서 액세스할 수 있으며, 예를 들어, LocalScript에 배치되면 오른쪽 마우스 버튼이 누르면 아래의 코드가 언제든지 Button2Down 출력됩니다.


local tool = script.Parent -- 이것이 도구 개체인지 확인하십시오
tool.Equipped:Connect(function(mouse)
mouse.Button2Down:Connect(function()
print("Button2Down")
end)
end)

세계 공간에서 마우스의 위치와 포인트 여부를 및 속성을 사용하여 찾을 수 있습니다.


Button2Up

이 이벤트는 플레이어가 오른쪽 마우스 버튼을 릴리스할 때 발생합니다.이것은 Tool에서 액세스할 수 있으며, 예를 들어, LocalScript에 배치되면 코드는 오른쪽 마우스 버튼이 릴리스될 때마다 Button2Up을 출력합니다.


local tool = script.Parent -- 이것이 도구 개체인지 확인하십시오
tool.Equipped:Connect(function(mouse)
mouse.Button2Up:Connect(function()
print("Button2Up")
end)
end)

세계 공간에서 마우스의 위치와 포인트 여부를 및 속성을 사용하여 찾을 수 있습니다.


Idle

마우스가 다른 마우스 이벤트에 전달되지 않는 모든 심장 박동 동안 발사됩니다.

참고, 이 이벤트는 마우스가 정지한 시기를 결정하는 데 사용되지 않아야 합니다. 매 심장 박동을 발사할 때마다 Mouse.Move 이벤트 사이에 발사됩니다.

For information on how to obtain the Mouse 개체에 대한 정보는 페이지 Mouse 를 참조하십시오.

개발자는 세계 공간에서 마우스 위치를 찾을 수 있으며, BasePartMouse.HitMouse.Target 속성을 사용하여 포인트하는지 여부를 확인할 수 있습니다.

개발자는 새로운 작업에서 UserInputService 대신 Mouse 개체를 사용하는 것이 좋습니다.


코드 샘플

This example demonstrates how mouse events are passed during each frame

Mouse.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", frame, "- mouse event was passed to", currentEvent)
end
for _, event in pairs(events) do
mouse[event]:Connect(function()
currentEvent = event
end)
end
RunService:BindToRenderStep("ProcessInput", Enum.RenderPriority.Input.Value, processInput)

Move

마우스가 이동되면 발사됩니다.

참고, 이 이벤트는 마우스 위치가 업데이트될 때 발생하므로 이동하는 동안 반복적으로 발생합니다.

For information on how to obtain the Mouse 개체에 대한 정보는 페이지 Mouse 를 참조하십시오.

개발자는 세계 공간에서 마우스 위치를 찾을 수 있으며, BasePartMouse.HitMouse.Target 속성을 사용하여 포인트하는지 여부를 확인할 수 있습니다.


mouse.Move:Connect(function()
local position = mouse.Hit.p
local target = mouse.Target
print(target, position)
end)

개발자는 새로운 작업에서 UserInputService 대신 Mouse 개체를 사용하는 것이 좋습니다.


코드 샘플

The example below allows the local player to move parts with their mouse.

When the player presses their left mouse button over a part, that part is the mouse's target and becomes the point. Until the player releases their left mouse button, that part will move to the mouse's world position when the player moves their mouse.

Note that the Mouse.TargetFilter property allows the code to ignore the part being moved when determining the mouse's world position.

The code should work as expected when placed in a LocalScript.

Move Parts with the Mouse

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

휠 백워드 이벤트는 마우스 휠이 뒤로 스크롤될 때 발생합니다.이 이벤트의 가능한 사용 방법에는 1인칭 슈터(FPS)에서 총의 조준경을 전환하거나 플레이어의 카메라를 확대하는 것이 포함됩니다.

이는 스크롤링 앞 이벤트와 함께 사용할 수 있습니다, Mouse.WheelForward .

For information on how to obtain the Mouse 개체에 대한 정보는 페이지 Mouse 를 참조하십시오.

개발자는 새로운 작업에서 UserInputService 대신 Mouse 개체를 사용하는 것이 좋습니다.


코드 샘플

The below example assumes that you have already got the player's mouse (and set it as a variable named 'mouse'), whether by use of a Tool, HopperBin or the Player:GetMouse() method. It will print "Wheel went backwards!" when the player scrolls backwards.

Mouse.WheelBackward

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelBackward()
print("Wheel went backwards!")
end
mouse.WheelBackward:Connect(onWheelBackward)

WheelForward

바퀴 앞으로 이벤트는 마우스 바퀴가 앞으로 스크롤될 때 발생합니다.이 이벤트의 가능한 사용 방법에는 1인칭 슈터(FPS)에서 총의 조준경을 전환하거나 플레이어의 카메라를 확대하는 것이 포함됩니다.

이는 스크롤백 이벤트와 함께 사용할 수 있습니다, Mouse.WheelBackward .

For information on how to obtain the Mouse 개체에 대한 정보는 페이지 Mouse 를 참조하십시오.

개발자는 새로운 작업에서 UserInputService 대신 Mouse 개체를 사용하는 것이 좋습니다.


코드 샘플

The below example assumes that you have already got the player's mouse (and set it as a variable named 'mouse'), whether by use of a Tool, HopperBin or the Player:GetMouse() method. It will print "Wheel went forward!" when the player scrolls forwards.

Mouse.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)