Lerp不能按预期工作,而是随着价值的增长而不是随着时间的推移平稳地前进

时间:2018-07-18 16:46:35

标签: c# unity3d

早安,

我正在开发一个游戏,当达到一定条件时,我想增加产生的粒子数量。现在,我选择使用lerp而不是一次全部显示它们,以便它们可以平滑地累积到该值。

尽管尽我最大的努力,我仍然无法使它顺利发生,并且过快地达到最大极限。 我已经发布了我的代码,希望有人指出我的方式中的错误。

void Update () {
    if (increaseLeaf==true)
    {

        var main = LeafStormParticleSystem.main;
        Debug.Log("here");
        main.maxParticles = (int)Mathf.Lerp(5, 150, counter);
        main.simulationSpeed = (int)Mathf.Lerp(1, 5, counter );
         counter += Time.deltaTime / 2;

        if (main.simulationSpeed == 5)
        {
            increaseLeaf = false;
        }
    }
    //counter += Time.deltaTime / 2;
    if (decreaseLeaf == true)
    {
        var main = LeafStormParticleSystem.main;

        main.maxParticles = (int)Mathf.Lerp(150, 5, decounter);
        main.simulationSpeed = (int)Mathf.Lerp(5, 1, decounter);
        decounter += Time.deltaTime / 2;

        if (main.maxParticles == 5)
        {
            decreaseLeaf = false;
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

当您使用lerp()时,您可以执行以下操作var num = new var(lerp(a,b));