

So it appears my problem is with the WAIT action. My problem is that when I use a WAIT action, it will not wait for 0.01666 seconds.įor whatever reason, it will wait for longer than 0.01666, and it's not giving me an accurate second-based countdown. This counts down so that the Suffix is a very quick countdown from 59 to 0 every second. I have a WAIT action, set to wait for 0.01666 seconds, after which it subtracts 1 from the suffix. I have the INTs labeled 'Prefix' and 'Suffix', so the String is created like this:

I have an FSM setup to convert 2 INTs to strings, which are shown as text on a canvas.

Thanks in advance, and I'll reply with results from any suggestions!īut, I guess I didn't explain my problem accurately. But I need it to count down in increments of 0.01666 seconds, and it just will not do it. When I change the WAIT state to 1 second, it perfectly counts down in 1 second increments. It will NOT count down in increments of 0.01666 seconds. I set the Project Settings -> Time -> Fixed Timestep to 0.01 and 0.016, and it doesn't fix the problem. Each 'second' actually take roughtly 1 1/2 seconds. I have a 'WAIT' state, that waits for 0.01666 seconds (the decimal value of 1/60 of a second). My problem is that I cannot make the game accurately count down a proper second. I've built the timer, and it works functionally, as in all the countdown digits behave as intended. In other words, 3 seconds would look like this:Īnd the '59' would rapidly count down (from 59 to 0 in one second) before changing to '1:59'. Public void Dispose() => timer.I've built a timer that is intended to display a countdown in seconds, while showing the decimal value of a second. Public void SetTime(int min, int sec = 0) => SetTime(TimeSpan.FromSeconds(min * 60 + sec)) Timer.Tick += new EventHandler(TimerTick) Private bool _mustStop => (_max.TotalMilliseconds - _stpWatch.ElapsedMilliseconds) string TimeLeftMsStr => void TimerTick(object sender, EventArgs e) Public TimeSpan TimeLeft => (_max.TotalMilliseconds - _stpWatch.ElapsedMilliseconds) > 0 ? TimeSpan.FromMilliseconds(_max.TotalMilliseconds - _stpWatch.ElapsedMilliseconds) : TimeSpan.FromMilliseconds(0) Private TimeSpan _max = TimeSpan.FromMilliseconds(30000) Public Stopwatch _stpWatch = new Stopwatch() Public class CountDownTimer : IDisposable Timer.StepMs = 77 // for nice milliseconds time switchĪnd don't forget to Dispose() when timer is useless for you Timer.CountDownFinished += () => MessageBox.Show("Timer finished the work!") Timer.TimeChanged += () => Label1.Text = timer.TimeLeftMsStr Usage: CountDownTimer timer = new CountDownTimer() (updated, because of problems with time calculation)
