Delay jump with yield doesn't work? [SOLVED]

The problem is simple but it seems the solution isn’t it would seem. I want my character to jump using

//the rest of the code as been omitted down to the jumping functions.

function Jump ()
{
	if (Input.GetAxis("Vertical")  Input.GetButtonDown ("Jump"))
         moveDirection.y = jumpSpeed;
	else
	{
		animation.CrossFade("standjump", 0.1);
		yield WaitForSeconds(0.3);
		StandingJump();
	}
}

function StandingJump ()
{
	moveDirection.y = stillJumpSpeed;
}

in short when the player presses the space bar, if they are moving the character will perform a leap forward at a set height. If, however, the character is standing still they will perform a jump at a different height using a more detailed animation.

The animation has anticipation with the character crouching into the jump. I want to stall or delay the jump until the animation has reached the right point.

I can’t.

Any yield that comes before the moveDirection.y will cause the script to just plain ignore it altogether.

I even tried setting an animation event to run

function StandingJump ()
{
	moveDirection.y = stillJumpSpeed;
}

on the lift off frame with no luck; still didn’t cause the jump to happen.

However, if I remove all the fancy code and just ask my character jump using moveDirection.y = stillJumpSpeed as soon as the button is pressed it works!

if there is a yield anywhere before the moveDirection.y it kills the whole thing.

Anyone got anything on this subject?

The main problem is that animation.CrossFade needs to be called on each frame (it’s not like animation.Play where you call it once and the animation keeps running). Instead of calling it in your jump script, you should set a variable with the name of the animation, but then call CrossFade with that animation from the Update function.

The solution was to create an if statement in the update function that was instantly called when the boolean jumpNow was true, which was only set after the yield.

Thus, allowing the animation to play up until the desired point and then performing the jump!

//variables omitted

function Update ()
{

//movement code omitted.

      // Jump!
		if (Input.GetAxis("Vertical")  Input.GetButtonDown ("Jump"))
			Jump();
		else if (!Input.GetAxis("Vertical")  Input.GetButtonDown ("Jump"))
		{
			StandingJump();
			animation.CrossFade("standjump", 0.1);
		}
		
		if(jumpNow)
		{
			moveDirection.y = stillJumpSpeed;
			jumpNow = false;
		}
   }
   
}

function Jump ()
{
    moveDirection.y = jumpSpeed;
}

function StandingJump ()
{
	yield WaitForSeconds (0.7);
	jumpNow=true;
}