- Home /
Animation finish completely?
Ive animated my gun so it has a sprint animation and then scripted that when shift is held down it plays and when let go off it stops. But when I let go of shift the animation stops where ever it is in the animation, instead of finishing the animation completely. How can I change my script so if shift has stopped being pressed it finishes the animation completely and leaves it in the starting position?
function Start () {
animation["gun run"].speed = 2;
animation["gun run"].wrapMode = WrapMode.Loop;
}
function Update () {
if(Input.GetKeyDown("left shift")){
animation.Play("gun run");
}
if(Input.GetKeyUp("left shift")){
animation.Stop("gun run");
}
}
Answer by NhommeBeurreOne · Aug 18, 2012 at 01:36 AM
The solution of your problem Blink can be a timer. You basically create a Timer that his length is equal to the sprint animation and you initiate it before the animation.play. You add an and comparison operator in the if statement that said : "if the Timer is equal to 0" then you can animation.Stop.
Best Regards,
Nb1
This is what Ive come up with but it has a few errors could you help me out? sorry about the formatting Unity should've fixed this by now.
var myTimer : float = 1.5;
function Start () {
animation["gun run"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop; animation["gun run"].speed = 2;
}
function Update () {
if(Input.Get$$anonymous$$eyDown("left shift")){ myTimer.Start; animation.Play("gun run"); }
if(myTimer <= 0){ animation.Stop;
} }
I don't have much time today for writing the script here's a tip : use Timer and a Cooler(hold the time of the animation). Use Timer -= Time.deltaTime for decreasing it. If you still have problem I'll try to write the script when I got a $$anonymous$$ute.
Answer by ScroodgeM · Aug 16, 2012 at 11:53 AM
animation["gun run"].wrapMode = WrapMode.Once;
instead of Stop()
not tested
Answer by vinod.kapoor · Aug 16, 2012 at 02:10 PM
you can use animation.Crossfade instead of animation.play that might work..