Does unity got a problem in measuring time?
I just solved a problem in my cycling code, but then another one appeared, and this one got one bug that i dont really know how to explain, but here it is: My code:
function Start () {
};
function Update () {
};
function continous () {
if (cicling < 1) {
Debug.Log("First part of the cycle");
};
else if (1 <= cicling && cicling < 2) {
Debug.Log("Second part od the cycle");
};
else if (2 <= cicling && cicling < 3) {
Debug.Log("Third Part of the cycle");
};
else {
Debug.Log("Fourth Part of the cycle");
cicling = -1;
}
};
var cicling : float = 0;
InvokeRepeating("cycle1", 0, 0.5);
InvokeRepeating("continous", 0, 5.0);
function cycle1 () {
cicling = cicling + 0.1;
};
for some uknown reason, in unity debug.log shows the message "third part of the cycle" twice. please help. :C
Answer by Positive7 · Sep 13, 2015 at 10:32 PM
#pragma strict
var cicling : float = 0;
InvokeRepeating("cycle1", 0, 0.5);
InvokeRepeating("continous", 0, 5.0);
function continous () {
if (cicling <= 1.0f) {
Debug.Log("First part of the cycle");
}
else if (cicling > 1.0f && cicling < 1.99f) {
Debug.Log("Second part of the cycle");
}
else if (cicling > 2.0f && cicling < 2.99f) {
Debug.Log("Third Part of the cycle");
}
else{
Debug.Log("Fourth Part of the cycle");
cicling = -1;
}
}
function cycle1 () {
cicling = cicling + 0.1;
}
Well, thats unexpected because the value "1.99" is included in the condition "< 2". But glad it worked.
Your answer
Follow this Question
Related Questions
function OnTriggerEnter using tags error 1 Answer
How would I load a new scene when a score that is scored in a string is reached? 2 Answers
UnassignedReferenceException: The variable closest of TAKE has not been assigned. 0 Answers
Do we still need to avoid foreach loops? 3 Answers
how to make a script that goes to the next scene if you click a gameobject in unity 5 2 Answers