【发布时间】:2020-02-08 08:27:48
【问题描述】:
所以,我目前在玩家屏幕上有一个按钮,当他们点击它时,它会检查玩家是否点击了世界上的任何地方,并将鼠标的点击坐标发送到服务器。当玩家点击鼠标左键时,服务器将使用这些来制作特定部件(它将很快与模型一起使用)移动到鼠标所在的任何位置。那工作得很好。但是,我想做到如果玩家在设置零件位置之前或之后点击字母“E”,它将基本上停止向服务器发送鼠标点击数据,然后继续前进。
我还在学习如何使用 UserInputService。 UserInputService.InputBegan 和 UserInputService.InputEnded 并没有像我希望的那样工作。有人可以帮我解决这个问题吗?
代码如下:
本地脚本:
userInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
movePartEvent:FireServer(math.ceil(mouse.Hit.X), math.ceil(mouse.Hit.Y), math.ceil(mouse.Hit.Z))
end
if input.UserInputType == Enum.KeyCode.E then
print("Part placed...")
--Exit the userInput part of the code here --
end
end)
服务器脚本:
local replicatedStorage = game:GetService("ReplicatedStorage")
local movePartEvent = replicatedStorage:WaitForChild("MovePartEvent")
movePartEvent.OnServerEvent:Connect(function(...)
local tuppleArgs = {...}
local player = tuppleArgs[1]
local value1 = tuppleArgs[2]
local value2 = tuppleArgs[3]
local value3 = tuppleArgs[4]
local function movePartOnEvent(part)
part.Position = Vector3.new(value1, value2, value3)
end
movePartOnEvent(game.Workspace.MovingPart)
end)
提前致谢!
【问题讨论】:
-
所以我决定改用 Mouse.KeyDown 函数。我刚刚了解到您仍然可以使用它。但是,我不介意仍然得到上面代码的答案,因为它将来可能会派上用场。谢谢。
标签: lua user-input roblox