Please Attach an Animation Clip!

Hi there,
I am new to Animations and have a few questions. Mainly that I just had my artist send over a simple power bar animation. What it does is, at start is an all Yellow bar. If played, the yellow is over taking, by red moving left to right. So, what I want to do is have the bar, power up, (animate) if the up btn is pressed.

Currently, if I press the up btn I get the message that…
Please attach an animation clip with the name ‘powerUp’ or call this function only for existing animations.

I have looked this up but nothing appears to me as an answer.

So I am wondering, what do I need to do to get this to fly? I think I need to use animationClip but again am a bit lost. Also, is there a way to reverse?

Thanks and sorry for the newbish questions.

Here is my code.
It is slightly modified from the docs.

var powerUp : AnimationState;
var powerDown : AnimationState;

function Start () {
	powerUp = animation["Take 001"];
	powerDown = animation["Take 001"];   
   
   powerUp.layer = 1;
   powerDown.layer = 1;	
   
   powerUp.blendMode = AnimationBlendMode.Blend; 
   powerDown.blendMode = AnimationBlendMode.Blend;   
   
   powerUp.wrapMode = WrapMode.Loop;
   powerDown.wrapMode = WrapMode.Once;
   
   powerUp.enabled = true;
   powerDown.enabled = false;
 
  powerUp.weight = 1.0;
   powerDown.weight = 1.0;
   
   powerUp.speed = 0.01;
   powerDown.speed = 0.01;
}

function Update () {
	if(Input.GetKeyDown("up"))
	{
		print("upKey");
		animation.Play("powerUp");
	}
	if(Input.GetKeyDown("down"))
	{
		print("downKey");
		animation.Play("powerDown");	
	}	
}

Note:
If powerDown is enabled = true, then the animation runs automatically.
If it is false, there is no animation.
No matter if powerUp is enabled or not, this effects nothing.
:.?

I think you need to declare animationclips instead of states

I just did,
However, in doing so I lose all my vars created in start. None are members of animationClip.

I am kinda rusty on animations now. I will get back to you soon.

ok.
I am studying the reference material but a little help would be muchos apprecioso.

Take a look here

Ok thanks I had not seen that page.
Will look at tonight or tomorrow.
Cheers.

Oh, my bad.
I had seen this. It is what i based my code off of.

I need to figure out why using an input to trigger my animation was causing an error, that error being that unity says i had no animation clip. I made adjustments but to no avail.

Play takes a string that is the name of an animation. You have no animation named “powerUp”

Ok right.
Thank you.
But I am confused. When I have this as my entire script…

function Update () {
	if(Input.GetKeyDown("up"))
	{
		print("upKey");
		animation.Play("Take 001");
	}
	if(Input.GetKeyDown("down"))
	{
		print("downKey");
		animation.Play("Take 001");	
	}	
}

It works, but I want to be able to control things like speed etc. Things that are manipulated thru AnimationState, so how do I go about making it so that animation “Take 001” can be slowed, stopped… anything that an animationState can handle.

:.?

The code to do it is

animation["Take 001"].speed = 0.5f;

ohhhh. thanks.
stupid me.

Currently I have…

function Update () {
	if(Input.GetKeyDown("up"))
	{
		print("upKey");
		animation.Play("Take 001");
	}
	if(Input.GetKeyDown("down"))
	{
		print("downKey");
		animation.Play("Take 001");	
	}	
}

acting as triggers, just to animate the only animation I have, but have stumbled upon an unexpected phenomenon. If I press Up the animation begins to play. If I press down before the animation finishes, there is no change, the animation must finish before the (same animation) but separate trigger is activated.

I would have thought that the running animation would be interrupted by the new instruction. No? Is this the case, but not here simply because it is the same animation that is working?

Try using Input.GetButtonUp to stop the animation.

Ok great, that works.

Right now, since I only have one animation, as in I have no “idle” animation, I am wondering, when I start it to say half way thru the full animation, then stop it, so it is essentially paused at the halfway point… The I restart it, I want it to start where it left off, however it resets to the beginning. How can I achieve this?

Try using animation.clip.length

But this is a read only and it seems to only read its full length. At least my print out was static, always the same. I would like to see its position (frame, position in animation) and take that into account when continuing the animation.