Home > Mobile >  why does float loop crash unity?
why does float loop crash unity?

Time:06-14

for (float Timer = 0f; Timer != 10f; Timer = unit   1f * Time.deltaTime) 

This is my code, I don't know why it crashes Unity.

CodePudding user response:

Because Timer won't be able to exactly be 10f. Float precision problem. And your Timer probably won't actually add. Instead, you should do the for-loop like this:

for (float Timer = 0f; Timer < 10f; Timer  = unit * Time.deltaTime)
{
    ....
}
  • Related