首页 > 解决方案 > 碰撞时淡出单个粒子?

问题描述

我目前正在尝试在碰撞时从粒子系统中淡出每个单独的粒子,但我很难让它工作。当前,当来自粒子系统的粒子与某物发生碰撞时,它开始褪色开始颜色(这是一个假设),并且它将继续与即将到来的粒子一起这样做。这些也需要在碰撞时淡出,而不是根据之前的粒子碰撞淡出。

这是目前的代码,非常欢迎任何建议。

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);
}

标签: c#unity3dparticle-system

解决方案


推荐阅读