Question by
sangifguangif · Sep 15, 2016 at 10:26 PM ·
timercountdown
Unity3d countdown timer is not counting down
I have run into a wall, i am trying to create a countdown timer but nothing seems to be working. The timer just displays a single number n doesnt count down(update). Checked everything in the inspector, all is set. I even used the log and it doesnt even count down there. Here is sample code for reference got from the unity official documentation.
using UnityEngine; using UnityEngine.Networking;
public class GuiLobby : NetworkLobbyManager { float countTimer = 0;
public override void OnLobbyServerPlayersReady()
{
countTimer = Time.time + 5;
}
void Update()
{
if (countTimer == 0)
return;
if (Time.time > countTimer)
{
countTimer = 0;
ServerChangeScene(playScene);
}
else
{
Debug.Log("Counting down " + (countTimer - Time.time));
}
}
}
Comment