【问题标题】:Unity: Destroy VFX Object after it finishes renderingUnity:完成渲染后销毁 VFX 对象
【发布时间】:2019-01-05 15:05:55
【问题描述】:

我正在关注这个 Unity(使用 C#)教程:Space Shooter,其中我们有一艘太空船,当小行星撞击它时会被摧毁。小行星被摧毁,爆炸视觉特效渲染成功。但是,此时不可见的爆炸物体会永远保留在场景中。我想清除它们。我知道这会起作用:

void DestroyObjectDelayed()
{
    // Kills the game object in 5 seconds after loading the object
    Destroy(this.gameObject, 5);
}

但我想知道是否有办法让对象在完成爆炸效果渲染时自行销毁,而不是我设置几秒钟。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您可以只使用粒子系统的持续时间。将它放在您想要在播放完毕后销毁的任何粒子系统上。

     public class DestroyParticles : MonoBehaviour
     {
         void Start()
         {
             Destroy(this.gameObject, GetComponent<ParticleSystem>().main.duration); 
         }
     }
    

    【讨论】:

    • ParticleSystem 没有名为 duration 的属性 .. 我确定您的意思是 GetComponent&lt;ParticleSystem&gt;().main.duration 参见 ParticleSystem.main -> MainModule
    • 它有效。谢谢!编辑答案以添加@derHugo 所说的内容
    • 谢谢大家。这一定是针对旧系统的。
    猜你喜欢
    • 1970-01-01
    • 2012-12-23
    • 2020-09-23
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多