Mouse
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Fareyi , daha geniş bir alanı kapsayan UserInputService ve ContextActionService ile çözüldü. Bu, daha geniş bir alanı kapsayan ve daha zengin özelliklere sahip olan çok daha fazla özellik içerir. Ayrıca, bu alternatifleri kullanmanızı önermiyor, ancak bu altern
Farenin Mouse nesnesi, öncelikle düğmelere ve raycasting için API'leri sunar. Arayüz, Player:GetMouse() çağrısındaki Players.LocalPlayer üzerindeki bir 1> Class.Tool.Equipped1> etkinliği aracılığıyla eri
- Kursoresin görünümünü değiştiren Icon özelliği için en çok bilinenidir.
- It continuous raycast the screen mouse position into the 3D world using the TargetFilter property, storing the results of the raycast in the Hit , Class.Mouse.Target|Target
-- Bir Yerel Koddan:local Players = game:GetService("Players")local player = Players.LocalPlayerlocal mouse = player:GetMouse()-- Farenin simgesini ayarlamamouse.Icon = "rbxasset://SystemCursors/Wait"
Not:
Bu nesne, işaretçi hareketini kontrol etmez/kısıtlar. Bunun için, UserInputService.MouseBehavior ve UserInputService.MouseDeltaSensitivity bakın.
Eğer iki işlev aynı giriş olayına bağlanırsa, örneğin Button1Down , both işlevleri etkinleştirilecektir. Bu davranış, etkinliklerin desteklemesi olmadığından görüşmez/geçiş işlevleri olarak i
Bir mouse'ın tüm platformlarda mevcut olmayabilir, fakat Mouse hala mobil (dokunmatik) ve konsol (gamepad) üzerinde işlevseldir, bu genellikle fare veya başlatıcı donanımı olmayan platformlar için geçerlidir. Açık kavşak davranışları için UserInputService ve ContextActionService kullanın.
Deneyiminizdeki girişleri özelleştirmek için Giriş ve Kamerası bakın.
Özet
Özellikler
3D alanındaki fare'nin pozisyonunun CFrame kaydı.
Mouse simgesi olarak kullanılan görüntünün içeriği ID'si.
A CFrame Class.Workspace.CurrentCamera ile yerleştirilmiş ve fare'nin 3D konumuna doğru yönlendirilmiştir.
3D alanındaki nesne, mouse olarak işaret ediliyor.
Class.Mouse.Hit ve Mouse.Target belirlenirken görmezden gelmesi gereken bir nesneyi (ve onun çızınları) belirler.
Mouse'ın işaret ettiği BasePart yüzeyinin Enu NormalId 'ini gösterir.
Bir Ray , fare'nin dünya pozisyonuna doğru yönlendirilmiştir, Workspace.CurrentCamera dünya pozisyonundan başlayan.
Oyun penceresinin genişliğini piksel olarak açıklar.
Oyun penceresinin yüksekliğini piksel olarak açıklar.
Ekranda konumunun X (yatay) bileşenini açıklar.
fare'un ekran pozisyonunun Y (vezgital) bileşenini açıklar.
Etkinlikler
Sol fare düğmesine basıldığında ateş edilir.
Sol fare düğmesi serbest bırakıldığında ateş eder.
Sağ fare düğmesine basıldığında ateş eder.
Sağ fare düğmesi serbest bırakıldığında ateşlenir.
Mouse'un başka bir mouse etkinliğine geçmesi sırasında her kalp atışında ateşlenir.
Fareniz hareket ettirildiğinde ateş edilir.
Farenin tekerleği geriye kaydırıldığında ateş eder.
Mouse轮anız ileriye yönlendiğinde ateş eder.
Özellikler
Hit
Bu özellik, 3D alanındaki fare pozisyonunun CFrame ını gösterir. Mouse.TargetFilter ve onun yerleşikleri göz ardı edilecek.
Geliştiriciler, şu şekilde Hit'in konumunu alabilir:
local position = mouse.Hit.Position
Çoğunlukla Tools tarafından kullanılır, bir silahı üçüncü kişi için farenin yönünü vurmak için ateş etmek.
Geliştiricilerin BasePart olanına sahip olduğunu gösteren farklı bir eylem gösterir.
Mouse.Hit nasıl hesaplanır?
Hit CFrame'in konumu, fare'nin içindeki Ray (geniş bir versiyonu) ile ilgili bir nokta olarak hesaplanır (Mouse.UnitRay'in bir parçası gibi).
Hit CFrame'in yönü, Mouse.UnitRay 'in yönüne eşittir.
local unitRayDirection = mouse.UnitRay.Directionlocal mouseHitDirection = mouse.Hit.lookVector-- unitRayDirection ≈ mouseHitDirection-- the vectors are approximately equal
Not, Workspace.CurrentCamera 'in yatışını hesaplarken Hit'in yönünü hesap etmek için kullanılmaz.
Farenin iç ışını 1,000 mil uzanır. Eğer fareniz 3D alanındaki bir nesneye işaret etmiyorsa (örneğin gökyüzüne işaret ettiğinde), bu özellik Workspace.CurrentCamera uzaktan 1,000 mil uzaktadır.
Kod Örnekleri
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.
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.
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
Simge bir özelliktir ve işaret edilen görüntüyü gösteren görüntüyü belirler. Boşsa, varsayılan bir ok kullanılır. Bir GuiButton kursörü'nün üzerindeki çizgi, bu özellik geçici olarak görmezden gelir.
Tüm kurumsal gizlemek için, bir透明 görüntü kullanmayın - yerine, UserInputService.MouseIconEnabled 'yi sağlayın.
Kullanıcıların deneyimlerindeki kullanıcı mouse icon'ını almak/ayarlamak için, UserInputService.MouseIcon kullanmalısınız. Mouse.Icon yeni API'nin kullanıcılarının mouse cursor'unu ayarladığı yeni API'den sonra kullanıcılarının fare kurşörünü de desteklemiyor.
Bir Cursor Tasarlanıyor
Kendi fare kursörlerinizi oluştururken şu kılavuzlar yararlı olabilir:
- Kullanılan görüntünün boyutu, kuruluştorun boyutunu belirler.
- Görüntünün ortası gdzie fare girişleri yapılır.
- Varsayılan fare görüntüsü 64x64 pikseldir, fare 17x24 piksel alanı kaplar.
System Cursors for PluginMouse
Class.PluginMouse ile çekilen Plugin:GetMouse() , gibi el, ok
<tbody><tr><td><img src="../../../assets/legacy/Mouse-Icon-Pointer.png"></img></td><td><code>rbxasset://SystemCursors/Arrow</code></td><td>Varsayılan tıklama ve seçme.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-PointingHand.png"></img></td><td><code>rbxasset://SystemCursors/PointingHand</code></td><td>Aktif bir bağlantıya/tuşa sorunaret edilmesi.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-OpenHand.png"></img></td><td><code>rbxasset://SystemCursors/OpenHand ]</code></td><td>Sürüklemeyi sağlayan öğeye fareyi koyarak.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-GrabbingHand.png"></img></td><td><code>rbxasset://SystemCursors/ClosedHand ]</code></td><td>Bir öğeyi sürükleme.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-IBeam.png"></img></td><td><code>rbxasset://SystemCursors/IBeam</code></td><td>Bir metin alanında gezinme.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeNS.png"></img></td><td><code>rbxasset://SystemCursors/SizeNS</code></td><td>Yatay yüklemeye genişletme işlemi yapmak için kaydırıcı.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeEW.png"></img></td><td><code>rbxasset://SystemCursors/SizeEW</code></td><td>Yatay yeniden boyutlandırma çubuğunun üzerine gezin.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeNESW.png"></img></td><td><code>rbxasset://SystemCursors/SizeNESW</code></td><td>Bir köşe üzerinde durmak resim etiketini yeniden boyutlandırır.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeNWSE.png"></img></td><td><code>rbxasset://SystemCursors/SizeNWSE</code></td><td>Bir köşe üzerinde durmak resim etiketini yeniden boyutlandırır.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeAll.png"></img></td><td><code>rbxasset://SystemCursors/SizeAll</code></td><td>Yönlendirici olarak değiştirmeye genel bak.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeSplitV.png"></img></td><td><code>rbxasset://SystemCursors/SplitNS</code></td><td>Yatay bir "ayırma" kolu üzerinde gezin.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-ResizeSplitH.png"></img></td><td><code>rbxasset://SystemCursors/SplitEW</code></td><td>Yatay bir "ayırma" kolu üzerinde gezin.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-Forbidden.png"></img></td><td> rbxasset://SystemCursors/Forbidden Yasaklandı</td><td>Kilitli/yasaklı bir öğeye fareyi koymak.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-Wait.png"></img></td><td><code>rbxasset://SystemCursors/Wait</code></td><td>Bir eylemin devam ettiğini gösterir.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-Busy.png"></img></td><td><code>rbxasset://SystemCursors/Busy</code></td><td>Sistemin meşgul olduğunu gösteren bir mesaj.</td></tr><tr><td><img src="../../../assets/legacy/Mouse-Icon-Crosshair.png"></img></td><td><code>rbxasset://SystemCursors/Cross</code></td><td>Bir pinpoint seçim alanına fareyi taşıyıcı olarak hareket ettirerek.</td></tr></tbody>
Görün\* | Varlık | Önerilen Kullanım |
---|
Bu görünümler yaklaşımlardır - asıl görünüm işletim sisteminize bağlıdır.
Kod Örnekleri
This example changes the Players.LocalPlayer mouse icon to look like a dragon image.
local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=163023520"
Origin
Orijin Mouse özelliği, fare'nin nereden geldiğini gösteren bir CFrame öğesi. Onu Workspace.CurrentCamera ile birlikte yerleştirir ve fare'nin 3D konumuna doğru yönlendirilmiştir.
Mouse.UnitRay başlangıç nızın aynı konumundan başlar ve aynı yönteki bir stud için uzanır.
local unitRay = mouse.UnitRaylocal origin = mouse.Origin-- unitRay.Direction = orijin.p-- unitRay.Direction ≈ origin.lookVector
3D alanındaki Mouse 'in pozisyonu için, Mouse.Hit 'i görün.
Kod Örnekleri
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.
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 alanındaki nesne, mouse olarak işaret ediliyor.
Not:
- Class.Mouse.TargetFilter ayarlandıysa, hedef filtresi ve onun aşağıdaki çocukları görmezden gelinir.
- Mouse bir BasePart için işaret etmediğinde, örneğin gökyüzüne işaret ettiğinde, Hedef sıfır olacaktır.
- 3D alanındaki farenin pozisyonunu arayan geliştiriciler Mouse.Hit kullanmalıdır.
Kod Örnekleri
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.
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
Bu özellik, Mouse.Hit ve Mouse.Target hesaplarını hesaplarken farenin değerini görmezden gelmek için bir nesneyi belirler. Öğenin soyundan soyundan soyundan soyundan soyundan soyund
Bu özellik herhangi bir Instance veya nil olarak ayarlanabilir, örneğin:
local Players = game:GetService("Players")local player = Players.LocalPlayerlocal mouse = player:GetMouse()mouse.TargetFilter = workspace.Model
Class.Player.Character|Character of the Players.LocalPlayer 'in mouse'un otomatik olarak görmezden geldiğini lütfen unutmayın.
TargetSurface
Bu özellik, farenin işaret ettiği Enum.NormalId yüzeşine ait olan BasePart değerini gösterir. Bu özellik, farenin konumunu ( Mouse.Hit ) ve işaret ettiği yeri ( 2> Class.Mouse.Target2> ) için derlenmiştir.
Bu özellik, fare bir parçaya işaret etmediğinde yanlış anlaşılır, örneğin fare gökyüzüne işaret ettiğinde. Bu özellik, şu anda bu koşullar altında "Sağ" olarak ayarlandı. Bu özelliği kullanmadan önce, farenin hedefi olup olmadığını kontrol edin.
local Players = game:GetService("Players")local player = Players.LocalPlayerlocal mouse = player:GetMouse()-- Farenin işaret ettiği bir bölüm olup olmadığını kontrol edinif mouse.Target thenprint("The mouse is pointing to the " .. mouse.TargetSurface.Name .. " side of " .. mouse.Target.Name)elseprint("The mouse is not pointing at anything.")end
Kod Örnekleri
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.
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 özelliği, 3D alanındaki fare pozisyonuna doğru <a href="/reference/engine/datatypes">Datatype.Ray</a> yönlendirir (Mouse.Hit tarafından açıklanmış). Onun CFrame kaynağındaki 1>Class.Camera.CFrame|CFrame1> ile ilgili. Tü
local Players = game:GetService("Players")local player = Players.LocalPlayerlocal mouse = player:GetMouse()print(mouse.UnitRay.Direction.magnitude) -- Always 1
ViewSizeX
ViewSizeX özelliği, oyun pencere boyutunun piksel cinsinden yatay bileşenini açıklar.
Kod Örnekleri
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.
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 öğesi, oyun pencereninin boyutunun piksel cinsinden yatay bileşenini tarif eder. Bu uzunluk, üst kısayolunuzun kullanılan alanını içerir.
Kod Örnekleri
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.
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)
Ekranda farklılıkları tespit ettiğinizde, ContextActionService:BindAction() ile Enum.UserInputType.MouseMovement veya UserInputService.InputChanged ile, bu iki de
X öğesi, ekranda fare'nin pozisyonunun yatay bileşenini açıklar. Pozisyon, üst kısma sol kısma göre ölçülür. Bu öğün Mouse.Y ile birleştirilebilir. Bu öğün Vector2 ile ürününüzü temsil edebilir:
local position = Vector2.new(mouse.X, mouse.Y)
Bu özellik Changed veya GetPropertyChangedSignal から gelen sinyali içermez. Bunun yerine Mouse.Move etkinliğini kullanın.
Kod Örnekleri
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.
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)
Ekranda farklılıkları tespit ettiğinizde, ContextActionService:BindAction() ile Enum.UserInputType.MouseMovement veya UserInputService.InputChanged ile, bu iki de
Y öğesi, ekranda fare'nin pozisyonunun yatay bileşenini açıklar. Pozisyon, üst kısma sol kısmına göre ölçülür. Bu öğün Mouse.X ile birleştirilebilir. Bu öğün Vector2 ile mouse'nin pozisyonunu temsil eden bir Class.Mouse.X ile kullanılabilir.
local position = Vector2.new(mouse.X, mouse.Y)
Bu özellik Changed veya GetPropertyChangedSignal から gelen sinyali içermez. Bunun yerine Mouse.Move etkinliğini kullanın.
Kod Örnekleri
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.
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)
Yöntemler
Etkinlikler
Button1Down
Button1Down, oyuncu sol fare düğmesine basınca bile ateş eder.
Ayrıca, bunun bir Tool dan da erişilebilir. Örneğin, bir LocalScript içine yerleştirildiğinde, aşağıdaki kod Button1Down herhangi bir sağ fare düğmesine basıldığında yazılır:
local Tool = script.Parent --Bunun bir Alet objesi olduğundan emin olun
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
print("Button1Down")
end)
end)
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve herhangi bir BasePart işaret ediyorsa, Mouse.Hit ve Mouse.Target özelliklerini kullanarak.
Mouse'un nesnesini nasıl alacağınızla ilgili bilgi için lütfen Mouse sayfasını görün.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
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.
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)
Button1Up
Sol fare düğmesi serbest bırakıldığında ateş eder.
For information on how to obtain the Mouse object, please see the Mouse page.
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve BasePart , Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi birine işaret ediyor.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
The follow example changes the BasePart.BrickColor of every BasePart the player clicks and releases their mouse on.
In order for a part to change color, the player's mouse must be over the part both when the player presses their left mouse button down and when the player releases their left mouse button.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local target = nil
local function button1Down()
target = mouse.Target
end
local function button1Up()
if target == mouse.Target then
target.BrickColor = BrickColor.random()
end
end
mouse.Button1Down:Connect(button1Down)
mouse.Button1Up:Connect(button1Up)
Button2Down
Button2Down, oyuncu sağ mouse düğmesine basınca bile ateş eder.
Ayrıca, bunun bir Tool dan da erişilebilir. Örneğin, bir LocalScript içine yerleştirildiğinde, aşağıdaki kod Button2Down her zaman sağ fare düğmesine basıldığında yazılır:
local Tool = script.Parent --Bunun bir Alet objesi olduğundan emin olun
Tool.Equipped:Connect(function(Mouse)
Mouse.Button2Down:Connect(function()
print("Button2Down")
end)
end).
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve herhangi bir BasePart işaret ediyorsa, Mouse.Hit ve Mouse.Target özelliklerini kullanarak.
Mouse'un nesnesini nasıl alacağınızla ilgili bilgi için lütfen Mouse sayfasını görün.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
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.
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.Button2Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
mouse.Target.BrickColor = BrickColor.random()
end
end)
end)
Button2Up
Sağ fare düğmesi serbest bırakıldığında ateşlenir.
mouse.Button2Up:Connect(function()
print("button 2 up!")
end
For information on how to obtain the Mouse object, please see the Mouse page.
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve BasePart , Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi birine işaret ediyor.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
The follow example changes the BasePart.BrickColor of every BasePart the player clicks and releases their right mouse button on.
In order for a part to change color, the player's mouse must be over the part both when the player presses their right mouse button down and when the player releases their right mouse button.
local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
local target = nil
mouse.Button2Down:Connect(function()
target = mouse.Target
end)
mouse.Button2Up:Connect(function()
if target == mouse.Target then
target.BrickColor = BrickColor.random()
end
end)
Idle
Mouse'un başka bir mouse etkinliğine geçmesi sırasında her kalp atışında ateşlenir.
Not, bu olay, fare hala durduğunda belirlemek için kullanılmamalıdır. Her bir kalp atışında Mouse.Move olayları arasında ateş edecektir.
For information on how to obtain the Mouse object, please see the Mouse page.
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve BasePart , Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi birine işaret ediyor.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
This example demonstrates how mouse events are passed during each frame
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
Fareniz hareket ettirildiğinde ateş edilir.
Not, bu olay, fare'nin konumu güncellendiğinde başlar, bu nedenle hareket edilirken tekrar başlar.
For information on how to obtain the Mouse object, please see the Mouse page.
Geliştiriciler, dünya uzayındaki farenin konumunu bulabilir ve BasePart , Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi birine işaret ediyor.
mouse.Move:Connect(function()
local position = mouse.Hit.p
local target = mouse.Target
print(target, position)
end)
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
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.
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
Maus轮向 döndüğünde oyun mouse'ınızın oyun dışında döndüğünde olan WheelBackward olayı tetikler. Bu olay için kullanılabilir kullanımlar arttırılmış erişim modu (FPS) veya oyuncukamerasının zoomlanmasıdır.
Bu, önüne kaydırma etkinliğiyle birlikte kullanılabilir, Mouse.WheelForward .
For information on how to obtain the Mouse object, please see the Mouse page.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
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.
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
Maus轮 önüne kaydırıldığında olan WheelForward etkinliği başlar. Bu etkinliğin için kullanılabilir kullanımlar arasında, bir silahın kaydırıcısını birinci kişi nişancı (FPS) içinde yeniden ayarlamak veya oyuncunun kamerasını yeniden ayarlmak bulunur.
Bu, önceki kayıt geri oynatma etkinliğiyle birlikte kullanılabilir, Mouse.WheelBackward .
For information on how to obtain the Mouse object, please see the Mouse page.
Not, geliştiriciler yeni çalışmada Mouse nesnesi yerine UserInputService kullanılmasını önerir.
Kod Örnekleri
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.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelBackward()
print("Wheel went forward!")
end
mouse.WheelForward:Connect(onWheelBackward)