Home > other >  How do I make an GameObject Instantiated from a prefab spawn some particles?
How do I make an GameObject Instantiated from a prefab spawn some particles?

Time:07-09

I would like this object to spawn some nice particles when destroyed. I did this:

[SerializeField] GameObject boom;

//↓ in void update, where it checks if it has 0 hp
GameObject explode = Instantiate(boom, transform.position, transform.rotation);

That wont work, as I cannot drag and drop the particle system into the inspector, it wont work, because prefabs are not stored in the scene. What do i do instead?

¯\_(ツ)_/¯

CodePudding user response:

So, you want the instantiated object to instantiate a particle effect when it dies? You could instead just make the particle effect a prefab and child the particle effect to the object so it is already in place when the object is instantiated. And then just call myParticleEffect.Play() when the object dies.

Seems like it may save you some time and effort if you simplify things.

For more on playing, pausing, stopping, e.t.c particle effects, check out the Unity Docs here.

  • Related