- Home /
Stopping and resuming an animation with script.
Hello.
Clicking causes the player to hold his/her hand up. I want to make it constantly held up while holding the mouse button down, and to go down when you let go.
function Update()
{
if( Input.GetButtonDown( "Fire2" ) ) {
animation.Play();
}
}
It's only using one animation of the hand going up and then down. It's 25 frames in all, and the point where I want to stop it is at 15 frames in. I'm new to scripting, and especially animation. Help, please.
Answer by StephanK · Apr 24, 2011 at 09:47 AM
In the Model Importer you can split that animation into a handup up and handdown animation. Then set the wrap mode to "clamp". If you play handup it will move the hand up and stay there. If you play handdown it lowers the hand.
Answer by Grady · Apr 24, 2011 at 09:55 AM
Yeah, i don't know if this would work, but, assuming that you have made your animations in the unity animation tool and they are in your project view, you could try:
function Update() { if( Input.GetButtonDown( "Fire2" ) ) { animation.Play("HANDUPANIMATION"); } else{ //hopefully would check to see if the right mouse button is not held down animation.Play("HANDANIMATIONDOWN"); } }
Yeah, as i said, there is no guarantees that this will work, as i have not tried this, but you can always give it a go...
Hope this helps...
-Grady
Your answer
Follow this Question
Related Questions
ANimation doesn't rewind on animation.Stop 3 Answers
Can the animation editor create local rotational data? 3 Answers
Only one animation playing NON-STOP!!? 2 Answers
Camera changes position when click on 3D text 2 Answers
Mouse Click Animation 3 Answers