首页 > 解决方案 > 照明亮度的 Lerp 不会逐渐增加

问题描述

minbrightness我的 Lerp 实现应该随着时间的maxBrightness推移逐渐增加光照。它确实改变了我的光线范围,但它会立即进入我的范围,maxBrightness而不是逐渐增加。我哪里出错了?

这是我正在使用的代码

private void Update()
{
    //this is a timer that will only only count down when collided = true
    if (_collided == true)
    {
        timeLeft -= Time.deltaTime;
        _light1.range = Mathf.Lerp(minbrightness, maxBrightness, lightTimer);
        //increases interloper
        lightTimer += _brightenRate * Time.deltaTime;
    }
    else
    {
        //this sets the lights range value to be bigger then normal
        _light1.range = Mathf.Lerp(maxBrightness, minbrightness, lightTimer);
        //increases interloper
        lightTimer += _brightenRate * Time.deltaTime;
    }

    //checks if the time value is 0
    if (timeLeft <= 0)
    {
        //this resets the value back
        timeLeft = timeLeftReset;
        _collided = false;
    }
}

我听说过IEnumerator,但不确定如何将它应用到我当前的解决方案中,或者这是否能解决我当前的问题。

标签: c#unity3dcoroutineienumerator

解决方案


推荐阅读