试图控制健康条的填充量。
有这个代码:
public float lerpSpeed = 2;
public void FillBar()
{
bar.fillAmount = Mathf.Lerp(0f, 0.7f, Time.deltaTime * lerpSpeed);
Debug.Log(emotion.fillAmount);
}
当函数运行时,在单击事件之后,bar.fillAmount 仅变为 0.28
你的问题在细节上有点空洞。但是你没有超过 0.28 的原因是因为 Mathf.Lerp 的第三个参数代表
两个浮点数之间的插值。
因此,为了获得正确的数量,您需要在每次填充条时设置一个变量并更新其中的值,最好是在协程或更新循环中。
public float lerpSpeed = 2;
private float t = 0;
public void FillBar()
{
bar.fillAmount = Mathf.Lerp(0f, 0.7f, t);
t += Time.deltaTime * lerpSpeed
}