简体   繁体   English

如何销毁游戏 object 但在 unity3D 之后有粒子效果?

[英]How can I destroy a game object but have a particle effect after in unity3D?

I am now making a simple game and when the enemy dies it emit particles.我现在正在制作一个简单的游戏,当敌人死亡时它会发射粒子。 But the problem is that once it has been destroyed then the particle effect stops.但问题是,一旦它被破坏,粒子效果就会停止。 Is there a way to solve this problem?有没有办法解决这个问题? Any help is greatly appreciated.任何帮助是极大的赞赏。 I am now using Unity 2019.3.9f1.我现在使用 Unity 2019.3.9f1。 Here is my code (enemy) -----这是我的代码(敌人)-----

private void OnCollisionEnter(Collision collision)
{

    if (collision.gameObject.CompareTag("bomb"))
    {
        GetComponent<ParticleSystem>().Play();
        Destroy(enemy);
    }
}

One option is to instantiate the particle system before destroying the gameObject (creating new GameObject), and assign a lifetime to this new GameObject:一种选择是在销毁游戏对象(创建新游戏对象)之前实例化粒子系统,并为这个新游戏对象分配生命周期:

Destroy(newGameObject, secondsToDestroy);

You can also do something similar to: https://answers.unity.com/questions/610673/how-to-destory-a-gameobject-in-c-after-3-seconds.html您还可以执行类似的操作: https://answers.unity.com/questions/610673/how-to-destory-a-gameobject-in-c-after-3-seconds.html

UPDATED更新

public ParticleSystem ps;

    // Start is called before the first frame update
    void Start()
    {
        GameObject go = Instantiate(ps.gameObject);
        Destroy(go, 10.0f);
        Destroy(this.gameObject);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么知道用 Unity3D 触摸了哪个游戏对象 - How can i know touched which game object with Unity3D 如何在Unity 3D中收集随机出现在场景中的硬币,收集后销毁游戏对象并在画布中显示分数? - How to collect coins in Unity 3D which appears randomly in the scene, destroy the Game Object after have been collected and show the score in canvas? 如何在Unity3d中使用触控来销毁单个对象? - How do I use touch control in Unity3d to destroy a single object? 如何使游戏对象从列表中删除? (Unity3d) - How to have a Game Object remove itself from a list? (Unity3d) Unity3D / Vuforia可以暂停图像目标或游戏对象吗? - Unity3D / Vuforia can PAUSE the image target or Game Object? Unity3D异步游戏对象实例化 - Unity3D async game object instantiation 在 Unity3d 引擎中编写游戏时,如何获取 android 中的滑动方向? - How can I get the swipe direction in android when coding a game in Unity3d engine? 如何在C#程序中运行“无头”(无GUI)Unity3D游戏? - How can I run a “headless” (no GUI) Unity3D game inside a C# program? 如何在 unity3D、C#、手机游戏中保存和加载关卡? - How I can save and load level in unity3D, C# , Mobile Game? Unity3D:一旦玩家在无尽的跑步者中沿 z 轴通过障碍物预制件的实例,我该如何销毁它们? - Unity3D: How can I destroy instances of an obstacle prefab once the player passes them on the z-axis in an endless runner?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM