【问题标题】:How to make objects disappear when they touch certain bricks in ROBLOX Studio?在 ROBLOX Studio 中,如何让物体在接触某些砖块时消失?
【发布时间】:2018-06-14 18:13:09
【问题描述】:

我正在尝试制作一个带有掉落块级别的 obby,并且砖块掉落得很好,但我希望它们在碰到某个块时消失,这样它们就不会看起来很乱。有什么帮助吗?

【问题讨论】:

    标签: scripting roblox


    【解决方案1】:

    假设每个掉落的部分都是一个新的部分,你可以简单地在被角色触摸时破坏该部分。

    script.Parent.Touched:connect(function(hit)
       if hit:FindFirstChild('Humanoid') then -- Check if it is a character that touched the part
          script.Parent:Destroy()
       end
    end
    

    【讨论】:

    • FindFirstChild('Humanoid') 不起作用 - 事件永远不会触发
    【解决方案2】:

    接受的答案不再起作用,这对我有用:

    script.Parent.Touched:connect(function(hit)
    
    if hit.Parent:FindFirstChildWhichIsA('Humanoid') then -- Check if it is a character that touched the part
        script.Parent:Destroy()
       end
    end
    )
    

    【讨论】:

      【解决方案3】:

      我想我知道出了什么问题。这是我的代码。

      local block = script.Parent
      local debounce = true
      
      block.Touched:Connect(function(hit)
          local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
          if humanoid and debounce == true then
              debounce = false
              block.Transparency = 0.5
              wait(1)
              block.Transparency = 1
              block.CanCollide = false
              wait(3)
              block.Transparency = 0
              block.CanCollide = true
              debounce = true
              
          end
      end)
      

      制作一个零件并将其命名为块,然后使用上面的代码插入一个脚本,它将完美运行。 (您可以通过多次复制粘贴“wait(1)”和“block transparent”并缩小数字来使其更流畅。示例:

              local block = script.Parent
              local debounce = true
      
      block.Touched:Connect(function(hit)
          local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
          if humanoid and debounce == true then
              debounce = false
              block.Transparency = 0.1
              wait(0.2)
              block.Transparency = 0.2
              block.CanCollide = true
              wait(0.2)
              block.Transparency = 0.3
              block.CanCollide = true
              wait(0.2)
              block.Transparency = 0.4
              block.CanCollide = true
              wait(0.2)
              block.Transparency = 0.5
              block.CanCollide = true
              wait(0.2)
              block.Transparency = 0.6
              block.CanCollide = true
              wait(0.2)
              block.Transparency = 0.7
              block.CanCollide = false
              wait(0.2)
              block.Transparency = 0.8
              block.CanCollide = false
              wait(0.2)
              block.Transparency = 0.9
              block.CanCollide = false
              wait(0.2)
              block.Transparency = 1
              block.CanCollide = false
              wait(3)
              block.Transparency = 0
              block.CanCollide = true
              debounce = true
      

      请注意我如何将 CanCollide 值设置为 true 直到某个点。这很重要,因为:一旦你触摸它,方块就会消失,没有给玩家跳跃的机会。相反,它消失得足够晚,让玩家有时间做出反应。

      【讨论】:

        猜你喜欢
        • 2011-05-14
        • 2023-02-07
        • 2021-08-06
        • 2016-12-28
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 2020-03-25
        • 1970-01-01
        相关资源
        最近更新 更多