【发布时间】:2020-04-13 14:40:09
【问题描述】:
我正在 Roblox Studio 上编写一个 obby。在这个 obby 中,我有角色跳跃的部分(这些部分大约是 10 x 10 螺柱)。
我想实现,当角色在某个部分时,该部分会改变颜色。
local platform = script.parent
local function changeColor(part)
local humanoid = part.Parent:FindFirstChild(‘Humanoid’)
if humanoid then
part.BrickColor = BrickColor.new(‘Bright red’)
end
end
local function restoreColor(part)
local humanoid = part.Parent:FindFirstChild(‘Humanoid’)
if humanoid then
part.BrickColor = BrickColor.new(‘Grey’)
end
end
platform.Touched:connect(changeColor)
platform.TouchEnded:connect(restoreColor)
这样做的问题是,当角色在零件上行走时,零件会随着每一步从灰色变为红色并变回。我希望该部分在玩家使用它期间保持红色。所以我想要这个功能来检查玩家是否在最后说的 0.5 秒内走过它,让玩家有时间行走而不恢复颜色。这是正确的方法吗,如果是,我将如何去做。是否可以覆盖触摸的功能?
这是它的样子(我后来稍微更改了代码,包括颜色等......但根本问题仍然存在)
【问题讨论】:
标签: lua overriding touch-event roblox