Problems with animation!!!

I have a simple axe and i got for it perfect animation and i put it on in and make a script…

#pragma strict

function Start () {

}

function Update ()
{
//Animation
if (Input.GetKeyDown (“w”))
{
animation.Play (“Axe_Animation”);
}
if (Input.GetKeyUp (“w”)
{
animation.Play (“Axe_Idle”);
}
}

And it show this error - MissingComponentException: There is no ‘Animation’ attached to the “Axe” game object, but a script is trying to access it.

I tried 3-5 methods of script and watched some videos but it doesnt work, someone please help me.

Format your code, please.

Its telling you whats wrong, you have not attached an animator component to the axe object, do this then assign both animations and try again. Hope I helped, if it doesn't work could you post some screenshots of the error and of the axe components.

i don't think there is any animator controller attached to "Axe" game object and if not you should watch a tutorials about it because there where variable should be and you change them from script to animate your game object.

It dont work. Spiceboy can u make me pls the animation when u moove axe go up and down and then put script togheter rightly and scene put here? I will be so thankful.

1 Answer

1

Hi:

What type of component are using for your animation?. For the code that your are using I can tell that you’re using the legacy “Animation”, so in order to make the animation work be sure to follow these steps:

  1. Attach an Animation component to the game object with the script that you’re trying to run the animation.
  2. Add the animation to the animation collection. Ensure that the name is “Axe_Animation” since that is how your script is trying to reproduce that.
  3. Ensure the animation has the “legacy” type. So, go to the inspector, on the right top most button change the inspector to be “Debug”, and change animation type to 1. The value 2 is used for the new Animators. I’m adding an image as reference.

[34967-animation+legacy.png|34967]

Hope this helps!