Unity 5.3 设置粒子系统发射率不变

Unity 5.3 Setting Particle System Emission Rate not changing

我查看了文档,但没有发现任何内容可以说明如何更改我的粒子系统中的发射率,我还查看了 Reddit,但没有找到任何内容。

这就是我想要改变的:

我认为可行的代码是这样的:

public ParticleSystem Smoke;


void Start()
{
    // Get the particle system (Smoke) Module.
    em = Smoke.emission;
    rate = em.rate;
    // Set the Mode to Constant.
    rate.mode = ParticleSystemCurveMode.Constant;

}

void Update()
{
    if (distance < 1f)
    {
        // Attempt to set the constant
        rate.constantMin = 20f;
        rate.constantMax = 20f;

    }
}

但是当我在场景视图和检查器中查看我的 GameObjects Particle Systems Emission 时,使用上面的代码没有任何变化。我做错了什么?

这在 5.3 中有点笨重。您必须获取汇率并将其存储在局部变量中,更改您想要的值然后进行设置。

void Update()
{
    if(distance < 1f)
    {
        rate = em.rate;
        rate.constantMin = 20f;
        rate.constantMax = 20f;
        em.rate = rate;
    }
}