能否编写脚本实现一个可移动的部件与模型接触时,模型一旦破坏就会消失?

我编写了一个按钮来生成模型,但我想知道是否可以编写一个脚本,当部件与模型接触时,模型就会消失呢?

点赞
用户2858170
用户2858170

当然您可以这样做。

使用 Roblox 的碰撞检测来触发它。

为 Touched 事件实现一个监听器,然后设置 BasePart 的 Transparency 属性为 1,将其变为不可见。让它爆炸或者任何你喜欢的方式。

https://developer.roblox.com/en-us/api-reference/property/BasePart/Transparency

https://developer.roblox.com/en-us/articles/detecting-collisions

https://developer.roblox.com/en-us/api-reference/class/Explosion

2021-04-19 19:16:08
用户15250066
用户15250066

你无法使用 .Touched 事件检测模型是否被触碰。最好的做法是将一个主要部件设置为模型(使用脚本或模型的属性)。然后在脚本中,你首先检测该部件是否被触碰:model.PrimaryPart.Touched:Connect(function()),然后遍历模型中的所有 部件(基本部件)并销毁它们:

for i, v in pairs(model:GetChildren()) do
  if v:IsA("BasePart") then
    v:Destroy() -- 或以你想要部件在模型中的形式消失
  end
end 
2021-04-20 23:10:01