倒数计时器未启动

时间:2019-04-29 21:29:54

标签: c# unity3d

我有下面的代码,并且我想为游戏结束剩余的时间做一个倒计时计时器。我必须读取serverTime值和endPlayTime值,但是我没有时间返回倒数计时器。

这是我的代码(已更新):

public void NewGameScore()
{
   ScorePCH = 0;
   TextoContador.text = "0";
   ES2.Save(ScorePCH, ScorePlayerCH);

   _bc.TournamentService.GetTournamentStatus(leaderboardId, versionId, successCallback2, failureCallback2);

    }

private void successCallback(string jsonResponse, object cbObject)
{
    var ZserverTime = JsonMapper.ToObject(jsonResponse)["data"]["server_time"];
    string _ZserverTime = ZserverTime.ToString();
    Debug.Log(_ZserverTime);
    PlayerPrefs.SetString("ZserverTime", _ZserverTime);

    var ZtPlayEnd = JsonMapper.ToObject(jsonResponse)["data"]["tournamentTimetable"]["tPlayEnd"];
    string _ZtPlayEnd = ZtPlayEnd.ToString();
    Debug.Log(_ZtPlayEnd);
    PlayerPrefs.SetString("ZtPlayEnd", _ZtPlayEnd);

    StartCoroutine("LoseTime");
    Time.timeScale = 1; //Just making sure that the timeScale is right
}

private void failureCallback(int status, int reasonCode, string jsonError, object cbObject)
{
    Debug.Log("Error al listar desafíos");
}

IEnumerator LoseTime()
{
    Debug.Log("ejecuta losetime...");

    long serverTime = Convert.ToInt64(PlayerPrefs.GetString("ZserverTime"));
    string _serverTime = serverTime.ToString();
    Debug.Log(_serverTime);

    long endPlayTime = Convert.ToInt64(PlayerPrefs.GetString("ZtPlayEnd"));
    string _endPlayTime = endPlayTime.ToString();
    Debug.Log(_endPlayTime);

    int StimeLeft = (int)(endPlayTime - serverTime);
    string _StimeLeft = StimeLeft.ToString();
    Debug.Log(_StimeLeft);
    //int StimeLeft = 120;

    while (true)
    {
        yield return new WaitForSeconds(1);
        StimeLeft--;
        countdown.text = ("" + StimeLeft);
    }

}

0 个答案:

没有答案