- Home /
Make the animation play at the start of the time waited, not the end of it?
I'm working on an FPS gun script, and i took the "reload" function from the script in the FPS tutotrial.
function Reload () {
yield WaitForSeconds(reloadTime);
if (clips > 0) {
clips--;
bulletsLeft = bulletsPerClip;
}
}
I added animation.Play like this:
function Reload () {
yield WaitForSeconds(reloadTime);
if (clips > 0) {
clips--;
bulletsLeft = bulletsPerClip;
animation.Play ("Reload"); // Line added.
}
}
The problem is that it plays the animation after the "WaitForSeconds". What should I do to make the animation play within the time span?
Answer by Statement · Dec 17, 2010 at 12:55 AM
Move the wait to after the animation starts. You probably also want to have it inside the clips test, and update bullets left after the wait is over.
function Reload () {
if (clips > 0) {
clips--;
animation.Play ("Reload");
yield WaitForSeconds(reloadTime);
bulletsLeft = bulletsPerClip;
}
}
If it would help you understand the flow of code, let's break down the Reload function into smaller parts:
function Reload () { if (clips > 0) { BeginReload(); yield WaitForSeconds(reloadTime); EndReload(); } }
function BeginReload () { clips--; animation.Play("Reload"); }
function EndReload () { bulletsLeft = bulletsPerClip; }
actually i tried that before,but the scripts still wont work.. the waiting part functions correctly, but it wont play the animation...
But you wrote: "The problem is that it plays the animation after the WaitForSeconds". $$anonymous$$ake sure the object has an animation and the animation has a clip called "Reload".
Okay, i got it working now (partially), but your answer is correct, it was some other animation's problem. Thanks!
Your answer
Follow this Question
Related Questions
Punch Animation Doesn't Work And Others Do... 1 Answer
Animation play when dead 2 Answers
Java Script: Clock script help. 1 Answer
Animation Script not working. 1 Answer
Animation Script Error 1 Answer