- Home /
Greater than and less than syntax problem
So I both of these in the Update function for the same script
if (slowMoMeter < 0 ) {
slowMoMeter=0;
}
if (slowMoState==true) {
if ( slowMoMeter > (Time.time- startTimer)) {
slowMoState1=true;
}
The code above doesn't work. When I investigated, I found that whenever I put my cursor next to one of the greater than or less than signs, it highlighted the other one. much like it would do for paired brackets or parenthesis. I don't want them to be paired, I just want them to be simple greater than and less than signs! Totally noob question but Please help!
I have no idea how this is connected to greater than and less than and your cursor, are you sure that is your issue?
To help you further we need to know this: What makes slow$$anonymous$$oState true? How do you increase slow$$anonymous$$o$$anonymous$$eter? Where do you set startTimer? Do you have an end curly brace to if (slow$$anonymous$$oState)?
Other than that, Jessy probably has the correct answer to your problem.
Answer by sarith · Jan 23, 2013 at 07:59 PM
Looks like you're just missing a closing curly brace "}" for your second if statement. This should work:
if (slowMoMeter < 0 ) {
slowMoMeter = 0;
}
if (slowMoState == true) {
if (slowMoMeter > (Time.time - startTimer)) {
slowMoState1 = true;
}
}
Also, you could refactor a bit as follows:
if (slowMoMeter < 0 ) {
slowMoMeter = 0;
}
if (slowMoState && (slowMoMeter > (Time.time - startTimer))) {
slowMoState1 = true;
}
I'm pretty sure they're unrelated conditionals -- but yes, if they're related, you can replace that second if statement with an else or if else
Relation doesn't matter. This particular second if will never be true if slow$$anonymous$$o$$anonymous$$eter is
Oh! haha -- sorry i didn't even look back at the code. #dumb
Your answer
Follow this Question
Related Questions
Disable function OnTriggerExit? 2 Answers
BEGINNER: why is my main menu not loading level 1 when I press play? 1 Answer
my prefab images dont appear in my scene view but are in my camera view 2 Answers
Enter Trigger, display Text, then delete object 1 Answer
Basic javascript array declaration 2 Answers