【发布时间】:2020-06-23 22:44:41
【问题描述】:
我最近将其中一些代码添加到我的 Roblox 游戏中。
local detector = script.Parent -- Store a reference to the detector.
function onTouch(part) -- The function that runs when the part is touched.
print('Shop Opened')
game.StarterGui.ScreenGui.Shop_Background.Visible = true
game.StarterGui.ScreenGui.Shop.Visible = true
end
detector.Touched:connect(onTouch) -- The line that connects the function to the event.
目前,当我加载到游戏中时,它通常会打印 shop opened 大约 17 次。 GUI 会打开并挡住屏幕。当我踏上检测器时,它也会打印“商店已开业”。如果我进入资源管理器并使可见等于 false,则该框未选中,但 gui 仍留在那里。有什么办法可以解决这个问题吗?
【问题讨论】:
-
确保您只执行该函数一次。通过检查它是否已被调用或在第一次运行时断开事件处理程序。我猜你多次触发了那个触摸事件。
标签: lua collision-detection roblox