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

时间:2016-03-12 21:25:38

标签: c# unity3d particle-system

我检查了文档,我没有发现如何在我的粒子系统中更改我的排放率,我检查了Reddit但什么也没找到。

这就是我要改变的地方:enter image description here

我认为可以使用的代码是:

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粒子系统发射时,上面的代码没有任何变化。我做错了什么?

1 个答案:

答案 0 :(得分:2)

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

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