从 60 秒开始倒计时

Count down from 60 seconds

我在 Unity3d 中使用此 C# 代码从零秒开始计数并显示结果并增加一个条,但现在我需要它从 60 秒开始倒计时,我已将值替换为 60 , 但它不起作用,它实际上是从 6 分钟开始倒计时。

void UpdateTime()
{
    currentTime -= Time.deltaTime / 60f;

    barAmount = (int)Mathf.Lerp(0f, 100f, currentTime);

    timeBar.valueCurrent = barAmount;


    float cTime = 60f * currentTime;

    TimeSpan timeSpan = TimeSpan.FromSeconds(cTime);

    timeTxt.text = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}",timeSpan.Days ,timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

    Debug.Log (timeTxt.text);
}

我做错了什么?

public String s;
public float currentTime = 60f;
private int barAmount;

void Update () {
   currentTime -= Time.deltaTime;
   barAmount = (int) Mathf.Lerp(0f, 100f, currentTime);
   // timeBar.valueCurrent = barAmount;
   float cTime = currentTime;
   TimeSpan timeSpan = TimeSpan.FromSeconds(cTime);

   s =  string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}",timeSpan.Days ,timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
}

我刚刚做了一个快速测试,它完美无缺。你不需要除以 60。Time.deltaTime 实际上是以秒为单位的。