【问题标题】:How do I get a signal once when I click单击时如何获得一次信号
【发布时间】:2021-10-21 05:07:45
【问题描述】:

我正在尝试构建一个构建系统,但是当我单击时,它会生成多个部分。

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- code
end
end)

【问题讨论】:

  • 这段代码看起来不错,当我测试它时,每次点击它只会触发一次。如果添加print 语句,InputBegan 函数是否每次点击触发两次?您的问题可能在其他地方。你有这个 LocalScript 的多个副本吗?
  • 我的错,我用了一个循环并把它放在里面

标签: lua roblox


【解决方案1】:

代码本身没问题,没什么问题。

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
    -- code
    end
end)

考虑检查事件是否只定义一次;避免在循环中绑定事件以防止内存泄漏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 2021-06-17
    • 2014-11-26
    相关资源
    最近更新 更多