我在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;
}
答案 0 :(得分:3)
使用Time.deltaTime
代替Time.time
并更改:
if (_time> 0.0f)
{...}
将_time = startTime
添加到Start()