所以,我目前在播放器屏幕上有一个按钮,当他们点击它时,它会检查玩家是否点击了世界任何地方,并将鼠标的点击坐标发送到服务器。然后,服务器将使用它们使特定部件(它很快就会与模型一起使用(转到玩家点击鼠标左键时鼠标所在的位置。这工作得很好。但是,我想让它到达如果玩家在设置零件位置之前或之后点击字母"E"的位置,它基本上将停止将鼠标命中数据发送到服务器,并继续前进。
我仍在学习如何使用UserInputService。UserInputService.InputStarted 和 UserInputService.InputEnd并不像我希望的那样工作。有人可以帮助我解决这个问题吗?
这是代码:
本地脚本:
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)
提前感谢!
我会添加一个变量来决定客户端是否仍在将数据发送到服务器。当您按"E"时,它将更改变量的值。
local movingPart = true;
userInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and movingPart 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...")
movingPart = false;
--Exit the userInput part of the code here --
end
end)
现在,当您按"E"时,它会停止将鼠标位置发送到服务器。如果要移动另一个部件,则必须再次将变量"movingPart"设置为true。