试图从此脚本中提取图像填充量。
public class ProgressBar : MonoBehaviour
{
public static int minimum;
public static int maximum;
public static int current;
public Image mask;
void Update()
{
GetCurrentFill();
}
void GetCurrentFill()
{
float currentOffset = current - minimum;
float maximumOffset = maximum - minimum;
float fillAmount = currentOffset / maximumOffset;
mask.fillAmount = fillAmount;
}
}我将解释这段代码:
当前=现值,最小=最低经验到水平,最大=最大经验到水平
if(skortotal < 20)
{
playerlevel = 1;
ProgressBar.minimum = 0;
ProgressBar.current = skortotal;
ProgressBar.maximum = 20;
}
if(skortotal >= 20)
{
playerlevel = 2;
ProgressBar.current = skortotal;
ProgressBar.maximum = 50;
ProgressBar.minimum = 20;
}
}代码已经起作用了,但我不知道如何使用lerp使其工作。
发布于 2020-09-18 16:53:57
您询问了如何使用Mathf.Lerp实现这一目标,下面是我的建议:
mask.fillAmount = Mathf.Lerp(minimum, maximum, current) / maximum;Lerp将自动夹紧这些值,因此结果总是在0..1内。
要让动画化,填充随时间的推移,您可以尝试以下操作:
float actualValue = 0f; // the goal
float startValue = 0f; // animation start value
float displayValue = 0f; // value during animation
float timer = 0f;
// animate the value from startValue to actualValue using displayValue over time using timer. (needs to be called every frame in Update())
timer += Time.deltaTime;
displayValue = Mathf.Lerp(startValue, actualValue, timer);
mask.fillAmount = displayValue;若要启动动画,请在更改actualValue时执行以下操作:
actualValue = * some new value *;
startValue = maskFillAmount; // remember amount at animation start
timer = 0f; // reset timer.https://stackoverflow.com/questions/63959125
复制相似问题