- Home /
Can/how do I set up a boolean to continue an animation after button press
Hello,
I am a newbie when it comes to this scripting thing, but I think I am getting an idea of the basics.
I've set my game up to where I press a button, an animation plays. However, the animation will stop playing when I let go of the button, and I want it to continue going after pressing once.
I'm thinking a boolean might be the way to allow that, but I could be radically wrong. but my basic idea is like:
//has button been released?
else= true
animation.Play("Fake animation name")
I hope that helps give an idea of what I am trying to accomplish. How would set up a script up so the animation will complete itself regardless of if I have my finger on the button?
Answer by zBlanco · Apr 02, 2013 at 08:30 AM
The boolean sounds about right.
This is what I would do:
var pressed: boolean;
function Update(){
if(pressed){
animation.Play("Animation Name");
}
}
function OnGUI(){
if(GUI.Button(new Rect(x, y, w, h), "Button Name")){
pressed = true;
}
}
It didn't recognize the x,y, w, h so I deleted only those, but it wouldn't play the animations when I pressed the button. When I checked the box it would, but it wouldn't stop playing it.
$$anonymous$$y goal is for the animation to play once, when the button is pressed, but not for it to depend on me holding the button down, or repeatedly pressing it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095514im_/https://answers.unity.com/themes/thub/images/avi.jpg)