- Home /
|| conditional statement not working
I can't the script below to work. It is attached to a game object which also has the "inciseS" script attached to it.
animation["inciseS"].speed = 1.75;
var itoggle : boolean = false;
function Update (){
if (Input.GetKeyDown(KeyCode.I))
itoggle = !itoggle;
if(itoggle)
animation.Play("inciseS");
else if(!itoggle || Input.GetKeyDown(KeyCode.R))
animation.Stop("inciseS");
}
The "R" key doesn't work to stop the animation; only the toggle button "I" is working to stop the clip. I have the "R" key assigned to toggle a clip on a different game object - could this be why?
Answer by testure · Sep 27, 2011 at 08:32 PM
Inside your last condition, you need to set itoggle to false. Because what's happening is that you're pressing R, it's stopping the animation, and then on the next frame it's restarting it because itoggle is still true.
got it to work, thanks testure!
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R)){
itoggle = false;
animation.Stop("inciseS");
}
I tried like this:
else if(!itoggle || itoggle && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R))
animation.Stop("inciseS");
or also like this:
else if(!itoggle || itoggle=false && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R))
animation.Stop("inciseS");
but it doesn't work; what am I doing wrong?
if you're using a sub condition you need to wrap additional parenthesis around it. for example:
if(true || (false && false))
Also- don't post comments as answers, it messes up search indexing ;)
Thanks again, and won't post comments as answers anymore, my bad.
Your answer
Follow this Question
Related Questions
some scripting help 2 Answers
How to use conditionals with delegates? 1 Answer
My backpack script doubt 0 Answers
Destorying despite IF Statement 1 Answer
Script Performance Questions 3 Answers