循环直到释放键或直到按下键

  • 本文关键字:释放 循环 lua roblox
  • 更新时间 :
  • 英文 :


我想为游戏制作一个延迟开关,我想知道如果我不需要等待7秒,我如何才能使它的效果,只要我按住右键,如果这是不可能的,也许它可以被按下,直到我再次按下它?我从一个教程,所以没有太多的lua知识,任何帮助非常感谢

代码:

setting = settings().Network
local Effect = Instance.new("ColorCorrectionEffect")
Effect.Parent = game.Lighting
Effect.Saturation = -1
Effect.Brightness = 0
Effect.Contrast = 0
Effect.Enabled = false
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.RightControl then
Effect.Enabled = true
setting.IncomingReplicationLag = 1000
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed * 3
wait(7)
Effect.Enabled = false
setting.IncomingReplicationLag = 0
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

您已经使用了InputBegan信号,您可以侦听inputendsignal以知道何时停止。

function onKeyDown(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.RightControl then
Effect.Enabled = true
-- ... do other things here
end
end
function onKeyUp(inputObject, gameProccessedEvent)
if inputObject.KeyCode == Enum.KeyCode.RightControl then
Effect.Enabled = false
-- ... do other things here
end
end
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(onKeyDown)
UIS.InputEnded:Connect(onKeyUp)

相关内容

  • 没有找到相关文章

最新更新