MissingComponentException (Animation) -How do I Fix?

MissingComponentException: There is no ‘Animation’ attached to the “Melee” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “Melee”. Or your script needs to check if the component is attached before using it.

That is the full error i get. I’m trying to animate a weapon so that it swings when i click the ‘melee’ button to damage the enemy. It is referring to this line of code:

animation.Play(“MaceAttack”);

I would very much appreciate a reply. I have scrapped my whole game and restarted and I still get that error. Oh, and the animation is attached to the gameObject ‘Mace’ and not ‘Melee’. When I attach the animation to Melee it does nothing.

So, sounds like you have two game objects, Mace and Melee. You have a script attached to the Melee game object, and the error you get is when this script uses the Play() API. It sounds like the animation is on your Mace object, so, your script needs to find the Mace object, and tell it to play the animation. To do this, in the Melee script code, add a GameObject, and in the inspector drop the Mace object onto it. Your Melee script can now see the Mace object. Then call animation.Play("MaceAttack") on the Mace game object.