0

我有一个由 Mathf Lerp 控制的填充量组件的图像。问题是,当时间尺度增加时,完成 Mathf Lerp 函数的时间比预期的要短。

当时间刻度等于 2 时,该功能应该花费一半的时间来完成,但它需要的时间会更少。知道为什么吗?

public static float demolishTime = 6.0f

public void OnClickDemolish()
{
    InvokeRepeating("demolishProgress", 0f, 0.1f);
}

void demolishProgress()
{        
    progress += (Time.deltaTime / demolishTime);
    demolishProgressBar[DemolishManager.demolishState].fillAmount = (float)Mathf.Lerp(0, 1, progress);
    if (progress >= 1) demolishCompleted();
}
4

1 回答 1

1

如果我错了,有人可能会纠正我,但这可能是因为 的第三个参数InvokeRepeatingrepeatRate 不受时间尺度的影响。

您可以考虑改用协程,如下所示:

public static float demolishTime = 6.0f;

public void OnClickDemolish() {
    StartCoroutine(demolishProgress());
}

IEnumerator demolishProgress() {
    float progressedTime = 0f;

    // Assuming 'demolishTime' is the time taken to entirely demolish the thing.
    while (progressedTime < demolishTime) {
        yield return new WaitForEndOfFrame();
        progressedTime += Time.deltaTime;
        demolishProgressBar[DemolishManager.demolishState].fillAmount = Mathf.Lerp(0, 1, progressedTime);
    }

    demolishCompleted();
}
于 2019-09-29T16:14:55.720 回答