Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 21, 2020 14:07
Show Gist options
  • Save openroomxyz/4c857eb9c6555bb83daaa31876e8fff8 to your computer and use it in GitHub Desktop.
Save openroomxyz/4c857eb9c6555bb83daaa31876e8fff8 to your computer and use it in GitHub Desktop.
Unity : How do we destroy gameObject and particle effect on it on destroy?
void KillEnemy()
{
ParticleSystem vfx = Instantiate(deathParticlePrefab, transform.position, Quaternion.identity);
vfx.Play();
float destroyDelay = vfx.main.duration;
Destroy(vfx.gameObject, destroyDelay);
//destroy patciles
Destroy(gameObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment