# unity how to make an animation reverse mid way through

I have a animation of several parts moving (think bridge) and would like the animation to reverse mid way through if a certain condition is modified (function call). I have the Animation and the AnimationClip which are added via a script.

Currently this is the code:

Animation anim;
public AnimationClip Open;
// Use this for initialization
void Start () {
anim = GetComponent<Animation>();
anim.AddClip (Open, "Open");
anim.Play ("Open");

}
void Update(){
Debug.Log ("update");
if (Input.GetKeyDown ("space")) {
rev ();
Debug.Log("reversing");
}
}
void rev(){
anim.Rewind()

}


However anim.Rewind() doesn't do what I want it to do it moves the animation back the the first frame rather then slowly move the animation backwards. I know there are some tricks involving the time or by changing the speed but I cannot figure those out either.

• I'm not really that familiar with Unity, but have you tried setting the animation speed to a negative value? – Alex Apr 30 '15 at 14:31
• I looked for that but anim.speed() doesn't seem to exist. – Thijser Apr 30 '15 at 14:52
• I don't think it's a function, rather a property. See here. – Alex Apr 30 '15 at 14:59