Animation reverse

Hi.

First, sorry for my lack of programming skills. I am a designer, and I just really want to make this one simple app work properly.
I have an object that has an animation. I also have two GUI buttons. I want the animation to play forward when I press the first button, and backwards when I press the other button. (There would be perfect if either the button changes texture for reverse and forward animation, or if it is not possible to press the forward button when that animation has played already :slight_smile:

So I have the javascript as this for the first button:

var kniv : AnimationClip;
var metaldel : AnimationClip;

function OnMouseDown () {
GameObject.Find(“kniv”).animation.Play(“kniv”);
GameObject.Find(“metaldel”).animation.Play(“diss2”);
}

Hope someone can help me :slight_smile:

Lasse

First off try making try making simple gui if statements. Your code doesn’t use any guis so right off the bat you can see that your code isn’t going to use those fancy shmancy buttons you’ve made.

function OnGui(){
	if(GUI.Button(Rect(10,70,50,30),"button 1")){
		// foward animation
	}
	if(GUI.Button(Rect(10,70,100,30),"button 2")){
		// backwords animation
	}
}

Then do some research to find out how to make an animation play backwords ( I only say this because i don’t know how myself).

It you can’t find out how to play an animation in reverse, just make two animations, one backwords one forwards.

I would suggest checking the unity script refrence for help on this.

Quishtay all the way.

Ok. I have tried a solution that worked half way. Im sure this can be done really simple, but this worked 50% at least.

var Box001 : AnimationClip;
var metaldel : AnimationClip;
var cubeRenderer : Renderer;

function OnMouseDown () {

if(cubeRenderer.material.color == Color.red)
cubeRenderer.material.color = Color.white;


else
GameObject.Find("Box001").animation.Play("kniv-sammen");
GameObject.Find("metaldel").animation.Play("diss2");
cubeRenderer.material.color = Color.red;

}

So when pushing the GUI texture this script is attached to it plays the animation if the color of the cube is white. When the color of the cube is red, it plays the last of the two animations “diss2” but not “kniv-sammen” I would like it to not play any of them if the color of the cube is red. Why is it playing one of the animations but not the other?

Lasse