Hello all! I’ve hit a bit of a bump in the road on this particular project of mine, and thought I’d turn to Unity Answers for help.
Basically I have this walk animation that plays when the ‘W’ key is being held. And I want a jump animation to interrupt it when the ‘space’ key is hit. The thing that I’m struggling with though is making the jump animation play at the 10th frame of the walk animation. What I mean is I want the animation to continue playing and then play the jump animation at the 10th frame. I tried using a while loop to make the jump animation yield until the walk animation got to the tenth frame, but it isn’t working. Here’s the code:
var forwardspeed:float=.5;
animation["run"].speed=1.4;
animation["walk"].speed=.1;
function Update (){
animation.CrossFade ("idle");
if(Input.GetKey(KeyCode.W)){
directionforward=Vector3.forward*forwardspeed*Time.deltaTime;
transform.Translate(directionforward*forwardspeed);
animation.CrossFade ("walk");
if(Input.GetKey(KeyCode.Space))
{
//plays the "walk jump" (jump specific to the walk)
walk_Jump();
}
}
function walk_Jump(){
//frames per second=24 This bit of code gets the current frame
var animationLengthWalk=animation["walk"].length;
var framelength=animationLengthWalk/20;
var animationLengthJump=animation["jump"].length;
var currentTime= animation["walk"].time % animationLengthWalk;
var currentFrame= currentTime*24;
if(currentFrame!==10){
//this should continue yielding until the walk animation's current frame equals 10
while(currentFrame!==10){
yield;
}
animation.Play("jump");
yield WaitForSeconds(animationLengthJump);
}
else{
animation.Play("jump");
yield WaitForSeconds(animationLengthJump);
}
}
What am I doing wrong here? Thanks in advance!