2

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);
}
Quincy Norbert
  • 431
  • 1
  • 6
  • 18
  • It looks to me like your FadeParticleSystem() is in a loop, yet does not account for any specific index i, so what it may do is repeat your color change across all particles several times. Maybe have a look at https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html to see how it's done with particular collisionEvents[i] – Philipp Lenssen Aug 17 '19 at 06:20

0 Answers0