I'm currently tring to fade out each individual particle from a particlesystem on collision, but I'm having a hard time getting it to work. Currently when a particle from the particlesystem collides with something it starts fading the start color(this is a asumption) and it will continuesly do so with the upcoming particles. These also need to be fading out when they collide, instead of fading out based on the previous particle collision.
This is the code as of now, any advice is very welcome.
void OnParticleCollision(GameObject other)
{
int collCount = _ps.GetSafeCollisionEventSize();
if (collCount > _collisionEvents.Length)
_collisionEvents = new ParticleCollisionEvent[collCount];
int eventCount = _ps.GetCollisionEvents(other, _collisionEvents);
for (int i = 0; i < eventCount; i++)
{
FadeParticleSystem();
}
}
private void FadeParticleSystem()
{
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[_ps.particleCount];
_ps.GetParticles(particles);
for (int p = 0; p < particles.Length; p++)
{
Color col = particles[p].color;
col.a -= col.a * 3 * Time.deltaTime;
particles[p].color = col;
}
_ps.SetParticles(particles, particles.Length);
}