Solution to Period == 0

I haven’t looked at the lecture solution yet, but this is what I did to protect against Time.time being divided by a period of 0.


I initialized the float “cycles” below the float “movementFactor”, just to group the floats initializations together, then in the Update() function, I made an if else branch to check if period is != 0f, if it is then I would divide Time.time / period, but if period is == 0, I just set cycles to 0f.

Edit: I changed the code to make use of mathf.epsilon for comparing the floats after watching the lecture.

Privacy & Terms