首页 > 解决方案 > 罗布乐思; 使损坏的部分重新出现

问题描述

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

标签: roblox

解决方案


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

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

推荐阅读