时间倒计时不会停在0:0.0,它永远不会到达else语句

时间:2016-05-12 10:58:55

标签: c# unity3d time unityscript

我在Update方法中使用else语句时遇到问题,而且我不知道如何让这个时钟停止。 S startTime只需几秒钟。如果你成功90.0f,你将有1.30分钟。问题是我需要在到达0:0.0时停止此时钟。

public Text TimerText;
private float startTime = 3.0f;
private bool start = false;
private float _time;
private float _minutes, _seconds;

// Use this for initialization
void Start ()
{
    start = false;
    startTime = 3.0f;
}

// Update is called once per frame
void Update ()
{
   // if (start)
  //  return;
    if (startTime > 0.0f)
    {
        _time = startTime - Time.time; // ammount of time since the time has started
        _minutes = (int)_time / 60;
        _seconds = _time % 60;
        TimerText.text = _minutes + ":" + _seconds.ToString("f1");
    }
    else
        Debug.Log("we are here"); 
}

private void CheckGameOver()
{
    Debug.Log("gameover");
}

public void StartTime()
{
    TimerText.color = Color.black;
    start = true;
}

1 个答案:

答案 0 :(得分:3)

使用Time.deltaTime代替Time.time并更改:

if (_time> 0.0f) 
{...}

_time = startTime添加到Start()

相关问题