- Home /
The question is answered, right answer was accepted
Animation Looping Help
Here is my scrpt
function Update () {
if(Input.GetKeyDown("mouse 0")) {
animation.Play("m4shoot");
}
if(Input.GetKeyUp("mouse 0")) {
animation.Stop("m4shoot");
}
}
When i let go of mouse 0 the animation stops even if its not done. Can you tell me so when you let go of mouse 0 the animation finishes instead of just stops.
What the... Why you closed the question? And with the reason that the right answer was accepted??? No answer is marked as accepted ...
Dude this way you won't get friends here. This page is like a wiki. It's a collection of good questions and good answers to help the community.
So i dont lose karma. I'm a begginer and since i have begginer questions they get thumbed down and i lose karma.
lol? you get karma if you accept an answer... It still can be downvoted...
There is no problem with beginner questions. The (old) FAQ states that no question is to "noob" as long as it has something to do with Unity and it's of interest to at least someone else on this planet.
Closing an unsolved question is the worst you can do! esp. with the wrong reason. That's why the old system only allows 3000+ users to close a question and only when it gets 5 votes to close.
Answer by HolBol · Jun 25, 2011 at 09:45 PM
Well, if you have a neutral animation, and a shoot animation, you would use animation.CrossFade(), if not, use animation.Pause.
Answer by Steven-Walker · Jun 25, 2011 at 10:07 PM
If you want the animation "m4shoot" to play fully, remove the key up handler that stops it!
function Update () {
if(Input.GetKeyDown("mouse 0")) {
animation.Play("m4shoot");
}
}
Answer by Bunny83 · Jun 25, 2011 at 10:23 PM
Shooting animations shouldn't be looping. You should handle that in your shooting logic. You would fire the animation everytime you shoot a bullet.
The point of looping animations is that they are never done so you need the animation to be a "normal" once-animation.
var rateOfFire = 5.0;
private var shootDelay = 0.0;
private var shootTimeOut = 0.0;
function Start()
{
var shootAni = animation["m4shoot"];
shootDelay = (1.0/rateOfFire);
// This will adjust the speed of the animation ot match the rate of fire
shootAni.speed = shootAni.length / shootDelay;
shootAni.wrapMode = WrapMode.Once;
}
function Update ()
{
if(Input.GetKey("mouse 0"))
{
if (Time.time > shootTimeOut)
{
shootTimeOut = Time.time + shootDelay;
animation.Play("m4shoot");
// shoot your bullet here
}
}
}
The code isn't tested but it should work that way ;)
I already have shooting script that has ammo and stuff. Yours would mess up what I have. Please just answer the question as asked.
That doesn't make any sense. A looping animation is NEVER done because it's looping. Stop will stop the animation at the current position. If you want the animation to stop at the end it have to be a non looping animation.
Follow this Question
Related Questions
How to play an animation in a loop? 2 Answers
Animations in the animator not looping 1 Answer
How to synchronize sound and animation loop? 2 Answers
Animation glitch when looping. 1 Answer
Looping animation while key down 1 Answer