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;
}
}