【问题标题】:Roblox; making destroyed parts reappearing罗布洛克斯;使损坏的部分重新出现
【发布时间】:2020-09-05 13:22:14
【问题描述】:

我制作了一个游戏,您可以在其中踩到特定的瓷砖,这部分会被破坏。我想让这个被破坏的方块在一定时间后重新出现,现在你可能想知道为什么我不让这个部分不可见并让它失去它的玩家碰撞。我没有这样做,因为我不知道如何在零件透明度 1 之上制作纹理。

【问题讨论】:

标签: roblox


【解决方案1】:

您可以制作零件的副本,然后进行销毁,几秒钟后将副本放回原处:

function onTouched(hit)
    -- see if it was a player that touched the part
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if (plr == nil) then return end

    -- make backup of the part and its parent
    local part = workspace.Part
    local backup = part:Clone()
    local backupParent = part.Parent    

    part:Destroy() -- do some cool effect for the destruction of it...

    spawn(function()
        wait(5)
        -- put part back in place
        backup.Parent = backupParent
        backup.Touched:Connect(onTouched)
    end)
end

workspace.Part.Touched:Connect(onTouched)

如果你只是想让它消失,你也可以通过将它的 Parent 设置为 nil 来临时将它从对象树中删除:

function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if (plr == nil) then return end

    local part = workspace.Part

    local backupParent = part.Parent    
    part.Parent = nil

    spawn(function()
        wait(5)
        part.Parent = backupParent
    end)
end

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2021-02-02
    • 2019-11-12
    • 2021-12-03
    • 2020-03-06
    • 2018-07-31
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多