[Solved] Reverse animation

Hello, I am trying to build a simple digger which has a movable digging arm. So far the movement of the arm runs off of an animation which is triggered by the down arrow key. The issue I am running into is that once the animation has reached the end, if I try to move the arm back up with the up arrow key it simply resets the animation to the frame 1 position instead of reversing the animation. If my description isn’t very helpful, hopefully you will understand what I am trying to achieve with my code.


Edit: I have managed to work out how to make my animation successfully pause when no keys are pressed, to play when the down key is pressed and to reverse when the up key is pressed. I am posting this code in hope that someone who needs it comes across it in the future.

var Bend_1:Transform;
var Bend1:AnimationState;

var B1A:boolean = false;
var B1B:boolean = false;

function Start(){
   	Bend1 = Bend_1.animation["Bend_1"];
   	Bend_1.animation["Bend_1"].wrapMode = WrapMode.ClampForever;
}

function Update(){
	
	if(Input.GetKeyDown("down")){
		B1A = true;
	}
	if(Input.GetKeyUp("down")){
		B1A = false;
	}
	if(Input.GetKeyDown("up")){
		B1B = true;
	}
	if(Input.GetKeyUp("up")){
		B1B = false;
	}

	if(B1A){
		Debug.Log("B1A = True");
		Bend1.speed = 1;
		Bend_1.animation.Play("Bend_1");
		if (Bend1.time < 0){
			Bend1.time = 0;
		}
	}
	if(B1B){
		Debug.Log("B1A = True");
		Bend1.speed = -1;
		Bend_1.animation.Play("Bend_1");
		if (Bend1.time > 1){
			Bend1.time = 1;
		}
	}
	if(!B1A && !B1B){
		Bend1.speed = 0;
	}
}

Unity3d animation speed is positive only. If you set it to anything below 0 it will assume 0. So you are telling it to play the first frame of the Bend_1 animation. You can do two things here to accomplish your task.

  1. Go back to the way you made the animation and create a second animation for the up process.

  2. Create a script that will loop through the animation and play the frames in reverse. Something like this might be a good reference Ideas for Animating while Paused? - Questions & Answers - Unity Discussions