1
\$\begingroup\$

Can someone say what is wrong with my code. I have custom timer implemented like this:

 float timeRemain = 10f;
 void Update(){
 timeRemain -= Time.deltaTime;
 if(timeRemain <= 0){
  ///...code here.
   }
 }

On PC it runs like expected but on Android device timeRemain variable becomes 0 in less then 10 secs. Who can suggest me what happens when i run it on Android device?

\$\endgroup\$
4
\$\begingroup\$

On some platforms the game actually starts running before the splash screen is gone. So this may give the illusion of a defective timer if you test it right at the start.

Another issue on slow devices is that your first frame of timer activation may have a very large deltaTime if other things happen at the same time.

For example if it takes 2 seconds to transfer all the textures and meshes to GPU memory on the first frame the timer is activated then the perceived display time will be 8 seconds because whatever was to be shown was invisible for the 2 seconds hang.

The deltaTime is the time the previous frame took.

Other than these two gotchas, deltaTime acts in an identical fashion on all platforms.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.