Created
November 6, 2013 06:49
-
-
Save areyoutoo/7331996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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