How to match the first position and orientation of an animation to the last ones of the previous animation

I want an the first position and orientation of a FBX animation to match to the last ones of the previous animation by the following script.


void Start() {		
  prevLastPos = new Vector3[animName.Length-1];
  prevLastAng = new Quaternion[animName.Length-1];
  for(int i = 0; i < animName.Length-1; i++){
    animation[animName*].enabled = true;*
 _animation[animName*].weight = 1.0f;*_
 <em>_animation[animName*].normalizedTime = 1.0f;*_</em>
 <em>_*animation.Sample();*_</em>
 <em><em>_prevLastPos *= transform.position;*_</em></em>
 <em><em><em>_prevLastAng *= transform.rotation;*_</em></em></em>
 <em><em><em><em>_animation[animName*].enabled = false;*_</em></em></em></em>
 <em><em><em><em>_*}*_</em></em></em></em>
<em><em><em><em>_*}*_</em></em></em></em>
 
<em><em><em><em>_*void Update () {*_</em></em></em></em>
 <em><em><em><em>_*if(!animation.isPlaying){*_</em></em></em></em>
 <em><em><em><em>_*if(curAnim > 0){*_</em></em></em></em>
 <em><em><em><em>_*transform.position = prevLastPos[curAnim-1];*_</em></em></em></em>
 <em><em><em><em>_*transform.rotation = prevLastAng[curAnim-1];*_</em></em></em></em>
 <em><em><em><em>_*}*_</em></em></em></em>
 <em><em><em><em>_*animation.Play(animName[curAnim]);*_</em></em></em></em>
 <em><em><em><em>_*curAnim++;*_</em></em></em></em>
 <em><em><em><em>_*if(curAnim == animName.Length) curAnim = 0;*_</em></em></em></em>
 <em><em><em><em>_*}*_</em></em></em></em>
<em><em><em><em>_*}*_</em></em></em></em>
<em><em><em><em>_*```*_</em></em></em></em>
<em><em><em><em>_*But it doesn't work. Appropriate values cannot be assigned in prevLastPos[] and prevLatAng[]. Does anyone know how to solve this problem?*_</em></em></em></em>

Thanks for your comment. As you have pointed out, I have modified the script as follows.


void Start() {	
  prevLastPos = new Vector3[animName.Length-1];
  prevLastAng = new Quaternion[animName.Length-1];
  while ( animation.GetClipCount() > 0 ){
    foreach (AnimationState state in animation){
      if ( state ){
        animation.RemoveClip( state.clip );
        break;
      }
    }
  }
  for(int i = 0; i < animName.Length-1; i++){
    animation.AddClip(animClip_, animName*);*_
 <em>_AnimationState state = animation[animName*];*_</em>
 <em>_*state.enabled = true;*_</em>
 <em>_*state.weight = 1.0f;*_</em>
 <em>_*state.normalizedTime = 1.0f;*_</em>
 <em>_*animation.Sample();*_</em>
 <em><em>_prevLastPos *= transform.position;*_</em></em>
 <em><em><em>_prevLastAng *= transform.rotation;*_</em></em></em>
 <em><em><em>_*state.enabled = false;*_</em></em></em>
 <em><em><em><em>_animation.RemoveClip(animName*);*_</em></em></em></em>
 <em><em><em><em>_*}*_</em></em></em></em>
 <em><em><em><em>_*for(int i = 0; i < animName.Length; i++){*_</em></em></em></em>
 <em><em><em><em><em><em>animation.AddClip(animClip_, animName*);*_</em></em></em></em></em></em>
 <em><em><em><em><em><em>_*}*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*}*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*```*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*But I have same results. Can't I get the last position in an FBX animation?*_</em></em></em></em></em></em>