[英]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.