Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 碰撞时淡出单个粒子?_C#_Unity3d_Particle System - Fatal编程技术网

C# 碰撞时淡出单个粒子?

C# 碰撞时淡出单个粒子?,c#,unity3d,particle-system,C#,Unity3d,Particle System,我目前正试图在碰撞时从粒子系统中淡出每个单独的粒子,但我很难让它工作。当前,当来自particlesystem的粒子与某个物体碰撞时,它开始淡出起始颜色(这是一个假设),并将继续淡出即将出现的粒子。这些粒子在碰撞时也需要淡出,而不是基于之前的粒子碰撞淡出 这是到目前为止的代码,任何建议都是非常欢迎的 void OnParticleCollision(GameObject other) { int collCount = _ps.GetSafeCollisionEventS

我目前正试图在碰撞时从粒子系统中淡出每个单独的粒子,但我很难让它工作。当前,当来自particlesystem的粒子与某个物体碰撞时,它开始淡出起始颜色(这是一个假设),并将继续淡出即将出现的粒子。这些粒子在碰撞时也需要淡出,而不是基于之前的粒子碰撞淡出

这是到目前为止的代码,任何建议都是非常欢迎的

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);
}
void OnParticleCollision(游戏对象其他)
{        
int collCount=\u ps.GetSafeCollisionEventSize();
if(collCount>\u collisionEvents.Length)
_collisionEvents=新粒子CollisionEvent[collCount];
int eventCount=_ps.GetCollisionEvents(其他,_collisionEvents);
for(int i=0;i
在我看来,FadeParticleSystem()处于循环中,但没有考虑任何特定的索引i,因此它可能会在所有粒子上重复多次颜色更改。也许可以看看如何处理特定的碰撞事件[i]在我看来,FadeParticleSystem()处于循环中,但不考虑任何特定的索引i,因此它可能会在所有粒子上重复多次颜色更改。也许可以看看它是如何处理特定碰撞事件的[i]