- Home /
Why will this timer not count down?
hello I cant figure why it wont count down it keeps debugging it saying timer at 70 i call this script from a different script and tell it to run the function reset and set howMany to a certain int same with timeAmount.
pragma strict
var howMany : int;
var theMain : GameObject;
var timeAmount : int;
var myTimer :int = 0;
function Update () {
if(myTimer >= 0){
myTimer -= Time.deltaTime;
Debug.Log("timer "+ myTimer);
}
if(myTimer < 0){
Debug.Log("timer finish");
// Result ();
if (howMany > 0)
theMain.GetComponent(furnace).Result();
howMany -= 1;
Reset ();
}
}
function Reset () {
Debug.Log("Reset");
myTimer = timeAmount;
}
Answer by Yofurioso · Jul 29, 2014 at 05:10 PM
The problem I think lies in line 9, you are substracting Time.deltaTime (which is a very very small float number) to an integer. Since myTimer is declared as int the value you are substracting gets rounded down before the operation, something like: 70 - 0.0005 turns into 70 - 0; To fix this simply change line 3 to "var myTimer : float = 0.0"
thanks for the answer I still seem to be having this same issue.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Targeting retical that changes color 1 Answer
Help with a faster clock? 1 Answer
Problem with forcing objects to a 2D plane 1 Answer
Timer ends game 1 Answer