Hello,
i have a game where I time/measure the reaction time of a player. After that i start a timer/counter which increases by Time.deltaTime and I display it as a string.
To ensure that the timer doesnt “overshoot” on low fps i wrote this code:
...
float timeCounter, reactionTime;
...
//This method gets called from Update()
void TimerMethodABC()
{
//Increase Timer for player
if (timeCounter < reactionTime && increaseTimer) {
timeCounter += Time.deltaTime;
timeCounter = (timeCounter > reactionTime) ? reactionTime : timeCounter; //Limit
player.DisplayTimer(timeCounter); // display in ui >> reactionTime.text = timeCounter.ToString("F2");
if(timeCounter >= reactionTime)
increaseTimer = false;
}
}
...
When i play my game in editor it works as expected, even if lock the fps down to 10.
As soon as i play it on my android phone it doesnt work as expected. The displayed time does overshoot the reactionTime.
Example:
reactionTime from the player => reactionTime = 1.9;
displayed time in the editor => 1.9
displayed time in the android build => 1.92 (for example)
I dont understand how this is actual possible when I set the TimeCounter equal to the reactionTime (if its higher) just one line before displaying it. Is there a better way to compare floats maybe?
I would appreciate any help.