I know how to make an explosion by emitting from the center of a sphere emitter with a positive start speed and an implosion by emitting from the shell of a sphere emitter with a negative start speed. What I want to accomplish is a change from an explosion to an implosion halfway through the duration of the particle effect. Does anyone know how I might be able to do this?
Here is a bit of code that immediately reverses the velocity of all the particles. It sets the lifetime of the particles to twice the wait time before reversing, and emits all the particles at once. That way all the particles disappear when they have contracted back to the origin.
using UnityEngine;
using System.Collections;
public class ReversePS : MonoBehaviour {
private ParticleSystem ps;
private ParticleSystem.Particle[] particles;
IEnumerator Start () {
ps = particleSystem;
ps.startLifetime = 6.0f;
ps.Emit (ps.maxParticles);
yield return new WaitForSeconds(3.0f);
Reverse ();
}
void Reverse () {
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.maxParticles];
int count = ps.GetParticles (particles);
for (int i = 0; i < count; i++) {
particles_.velocity = -particles*.velocity;*_
* }*
* ps.SetParticles(particles, count);*
* }*
}
Note the idea of reversing the particles speed over time is a bit more complicated than my comment above indicates. Since particles are deleted by Unity for a variety of reasons, the code would have to take set (and not get) the particles each frame. And the code would need to take over movement of particles during the transition.