首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我试图通过监控脚本的所有子部分,让“叶子”在Roblox游戏中产生沙沙作响的噪音。

我试图通过监控脚本的所有子部分,让“叶子”在Roblox游戏中产生沙沙作响的噪音。
EN

Stack Overflow用户
提问于 2021-10-27 22:14:06
回答 1查看 87关注 0票数 0

使用another question中的儿童监控脚本@Kylaaa,我花了几个小时在这上面,改变了核心功能,从修复和消失的砖块到当玩家“穿过树叶”时播放父母的声音。我一直在研究这个问题的各个方面('IsA','TouchInterest','If...then',类,运算符等),并做了各种事情,例如修改我的脚本以查看被触摸对象的名称,而不是它们的类,但我没有幸运地播放声音。

代码语言:javascript
复制
-- create a helper function to access the brick and the thing that touched it
function OnTouched(thing)
    local active = false --start with this debounce variable off so that the function will run the first time
    return function(target) --provides actual target of the event
        if active then return end       -- do not do the animation again if it has already started
        local player=thing.Parent:findFirstChild("Humanoid") --determine if it's humanoid
        if player then --if it is, then
            active = true --toggle to prevent function from running again simultaneously
            script.Parent:play() --play rustling leaves sound
            wait(1)
            active = false -- reset so function can be used again
        end --end of if statement
    end
end

-- loop over the children and connect touch events
local bricks = script:GetChildren()
for i, brick in ipairs(bricks) do
    if brick:IsA("Part") then
        local onTouchedFunc = OnTouched(brick)
        brick.Touched:Connect(onTouchedFunc)
    end
end

这是我想添加沙沙声的落叶层的一张照片。我在左边的藤条上也有同样的问题。

葡萄藤:

所有的叶子都是'MeshParts‘,里面有'SurfaceAppearance’,并且是锚定的和CanTouch,但不是CanCollide。我试着打开CanCollide,但没用。

密集叶面片属性:

表面外观特性:

我试过"if brick:IsA("Model“或"MeshPart") then”和"if brick.Name=="Dense Leaf patch“或"SurfaceAppearance”或"DenseLeafPatch“then”,但这两种方法都不起作用。

然后我注意到TouchInterest不是由Roblox生成的,我知道你既不能复制也不能复制TouchInterests在你需要的地方使用(根据DevForum中的一条消息,它们不是为开发人员准备的)。

我最初在单独的模型中有1-3个叶子'MeshPart's,但后来做了一个单独的,不可见的部分(名称: TouchInterest),CanTouch而不是CanCollide,它大到足以覆盖几乎所有实例的物理区域,并将所有的MeshParts放到那个部分中。然后,我修改了脚本,只查找‘部分’。结果,在运行时生成了一个TouchInterest。

这是“叶子”组中涉及的所有内容,包括声音,然后是脚本,包含部分,然后是里面的所有叶子,作为脚本的孩子。

声音的属性:

输出中没有与此相关的错误。

我觉得有些简单的东西我不明白。我需要几个小的部分(而不是一个大的部分)来包含树叶组吗?请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2021-10-29 12:37:20

我发现了问题所在。

  1. 在第6行,我使用了"thing“,而我应该使用”

“。

  1. 在第9行,我忘记了大写”Play“。
  2. 在第10行,我需要等待2秒而不是1秒。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69746061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档