Blending two animations in a sequence?

Hello,

this is my first post in the answers, although I have been reading a lot of information trying to find the information that I could need to solve myself the answer.

For a combat system that I am implementing that includes single strikes and combos, i need in the case that the player is keychaining strikes to blend the animations, eliminating part of the beginning of some clips and the end of others as to create a smooth transition between them controlled within predefined frames.

I have reached a code that should be work, but the problem is that for some reason unknown to me, the animationstate.time doesn´t seem to keep track the running of the animations.

void blend_animations(string animation1, string animation2, float frame end_clip1, float frame begin_clip2)
{
    

    float fr=animation[animation1].clip.frameRate;



    animation[animation1].time = 0.0F;
    animation[animation1].wrapMode = WrapMode.ClampForever;
    animation[animation1].weight = 1.0F;
    animation[animation2].weight = 0.0F;
    animation[animation1].speed = 1.0f;
    animation[animation2].speed = 1.0f;

  float frameTime=(end_clip1/fr);
 	

  animation[animation1].enabled = true;
  animation[animation1].time = 0.0f;

  animation.CrossFade(animation1);
 	

   
    if(animation[animation1].time >= frameTime)
    {
    //Pause 1st animation
    animation[animation1].speed = 0.0f;
    animation[animation1].weight = 0.0F;
    animation[animation2].weight = 1.0F;
    frameTime=begin_clip2/fr;
    animation[animation2].time = frameTime;
    animation[animation2].enabled = true;
    animation.CrossFade(animation2);
 
 	 
   }
}

The condition within the if is nether executed because the animationstate.time for the first animation doesn’t update and stays with a value of zero.

What am I doing wrong? Is there an easier way to do it?

Cheers,

D.

Well, I have been able to make some progress, and the new function to work with some consistency, but with some random freezes that I am not able to understand what could be cause them.

Can any one, help me fixing or improving it?

Regards,
D.

void blend_animations(string animation1, string animation2)
	{
    //Enable animations

    float fr=animation[animation1].clip.frameRate;
    AnimationState tempState;

    if(!animation.IsPlaying(animation1)) 
    { 
    		
 
    animation.CrossFade(animation1,0.0f,PlayMode.StopAll);

    }
    
float currentTime=animation[animation1].time;



    animation[animation2].time = (begin_clip2/fr);



    if(animation[animation1].time >= (end_clip2/fr))
    {
   
   	animation[animation1].weight = 0.0F;
    animation[animation2].weight = 1.0F;
    animation[animation2].time = (0.09f/fr);
    animation[animation2].enabled = true;
    if(!animation.IsPlaying(animation2)) 
         animation.CrossFade(animation2,0.0f,PlayMode.StopAll);
     }





    
   }



	
	
}