Is this currently the best way to make a timer? Will it be consistent across devices and different frame rates?
float timeLeft = 10f;
function Update()
{
timeLeft -= Time.deltaTime;
if ( timeLeft < 0 )
{
GameOver();
}
}
Is this currently the best way to make a timer? Will it be consistent across devices and different frame rates?
float timeLeft = 10f;
function Update()
{
timeLeft -= Time.deltaTime;
if ( timeLeft < 0 )
{
GameOver();
}
}
That will generally work, but Time.deltaTime is affected by the timescale, and I think it gets impacted if the game is slowing down due to hitting Maximum Allowed Timestep (not sure on that one). Time.unscaledTime might be the better choice, or possibly DateTime.Now().