我试图在游戏开始时填写图像,我得到正确的时间值,但我无法将这些值(3 ... 0)转换为(0 .... 1)要填充图像,就像3秒钟一样,图像将在3秒后填充。到目前为止,这是我的代码。
private float total_time = 3.0f;
private float end_time;
private float time_change_at;
private float init_time;
void Start()
{
init_time = Time.time;
end_time = init_time + total_time;
time_change_at = total_time - 1.0f;
}
void Update ()
{
if (total_time <= 0.0f)
{
return;
}
total_time = end_time - Time.time;
if (total_time >= time_change_at)
{
time_change_at = time_change_at + 1.0f;
}
fill_the_bar(total_time);
string time_to_show = Mathf.Floor((total_time/60.0f)).ToString("00")+":"+(total_time%60).ToString("00");
print (time_to_show);
}
public void fill_the_bar(float val)
{
here i want to fill image gradually
//image.fillAmount
}
答案 0 :(得分:1)
您可以使用Math.abs(total_time - 3.0f) / 3.0f
来反转计数,其中3.0f是计数器的max_time
。
public void fill_the_bar(float total_time)
{
float max_time = 3.0f
image.fillAmount = Math.Abs(total_time - 3.0f) / 3.0f
}