Skip to content

Instantly share code, notes, and snippets.

@areyoutoo
Created November 6, 2013 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save areyoutoo/7331996 to your computer and use it in GitHub Desktop.
Save areyoutoo/7331996 to your computer and use it in GitHub Desktop.
public class ImplodingEmitter : MonoBehaviour {
void Start() {
StartCoroutine(Implode());
}
IEnumerator Implode() {
if (!particleSystem.isPlaying) {
particleSystem.Play();
}
//let the system do it's thing for a bit
yield return new WaitForSeconds(3f);
//stop emission
particleSystem.emissionRate = 0f;
//allocate reference array
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount];
//this loop executes over several frames
// - get particle list
// - update each particle's position
// - set particle list
// - wait one frame
for (float t = 0f; t < 1f; t += 0.1f) {
int count = particleSystem.GetParticles(particles);
for (int i=0; i<count; i++) {
particles[i].position = Vector3.Lerp(particles[i].position, transform.position, t);
}
particleSystem.SetParticles(particles, count);
yield return null;
}
//once loop is finished, clear particles
particleSystem.Clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment