1

如果玩家进入触发区,我想在 Unity 中将两个粒子系统的起始颜色从一种颜色转换为另一种颜色。我试图用 Color.Lerp 来做,但结果是它“滞后”,这意味着它之间只有 3 种颜色。我的代码:

public IEnumerator animateTriggerEnter(float duration = 0.1f)
{
    float elapsedTime = 0f;
    float lerp = 0f;
    while (lerp <= 1f)
    {
        elapsedTime += Time.deltaTime;
        lerp = elapsedTime / (float) duration;
        topParticle.startColor = Color.Lerp(standardColor, triggerColor, lerp);
        botParticle.startColor = Color.Lerp(standardColor, triggerColor, lerp);
        yield return null;
    }
}

对于 value lerp,我总是得到相同的 6 个值,但不应该更多吗?它也仍然滞后,持续时间更长。

4

1 回答 1

0

First of all I'd try isolating

Color.Lerp(standardColor, triggerColor, lerp);

and testing it's speed Stopwatch? If I am right lerp is noting more than

result=startValue + (endValue - startValue) * lerpValue;

In that case + 1 constructor execution. According to MSDN math itself will should take less than

lerp = elapsedTime / (float) duration;

Are you sure it's lerp problem?

于 2016-02-22T06:56:29.943 回答