- Home /
Question by
mohd-ma · Jun 19, 2014 at 10:23 PM ·
if statement
if statement problem !
hello , i face a problem in my code the if statement doesn't work !! But if i wrote (myTimer <= 10) it work perfect . My code :
var myTimer : float = 100;
function Update() {
myTimer -= Time.deltaTime;
if (myTimer == 10) {
Application.LoadLevel(Application.loadedLevel);
}
}
Comment
Best Answer
Answer by Bunnybomb7670 · Jun 19, 2014 at 10:28 PM
Time.deltaTime is not increasing or decreasing at a uniform rate if the Framerate is not stable, this means that the value will not always be 0, 1, 2, or so, it could be 1.32324213423 or something, your code wants to know if the timer is EXACTLY at the value 10. A way you can do this better is to check if (more than or equal to) myTimer >= 10. OR (less than or equal to) myTimer
Check : http://docs.unity3d.com/ScriptReference/Time-deltaTime.html for more info on Time.deltaTime and its purpose.
thanks for your explanation , i,ll use (more than or equal to).