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?

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;
}