C# 照明亮度的Lerp不是逐渐增加的
我对Lerp的实现应该随着时间的推移逐渐将灯光从C# 照明亮度的Lerp不是逐渐增加的,c#,unity3d,coroutine,ienumerator,C#,Unity3d,Coroutine,Ienumerator,我对Lerp的实现应该随着时间的推移逐渐将灯光从minbrightness增加到maxBrightness。它确实改变了我的灯光范围,但是它会立即转到我的maxBrightness,而不是逐渐增加。我哪里出错了 以下是我正在使用的代码 private void Update() { //this is a timer that will only only count down when collided = true if (_collided == true) {
minbrightness
增加到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;
}
}
private void Update()
{
//这是一个计时器,只有当Collide=true时才会倒计时
如果(_collide==true)
{
timeLeft-=Time.deltaTime;
_light1.range=Mathf.Lerp(最小亮度、最大亮度、lightTimer);
//增加闯入者
lightTimer+=\u BrightRate*Time.deltaTime;
}
其他的
{
//这将灯光范围值设置为大于正常值
_light1.range=Mathf.Lerp(最大亮度、最小亮度、lightTimer);
//增加闯入者
lightTimer+=\u BrightRate*Time.deltaTime;
}
//检查时间值是否为0
如果(timeLeft在我看来很好。你的\u brightRate
值可能太大。如果它是一个序列化字段(如果你使用[SerializeField]
和/或public
),如果你没有在代码中的某个地方设置它,请确保你在检查器中设置它。@Ruzihm\u brightRate是0.5f