I just started creating my first game using Unity and I already stucked. I tried to animate a mace and run the animation when the left mouse button is clicked, but I’m getting this strange error:
MissingComponentException: There is no 'Animation' attached to the "Mace" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "Mace". Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Animations.cs:569)
MeleeSystem.Update () (at Assets/MeleeSystem.js:11)
Reffering to this script:
#pragma strict
var theDamage : int = 50;
var Distance : float;
var maxDistance : float = 1.5;
var TheMace : Transform;
function Update (){
if(Input.GetButtonDown("Fire1")){
TheMace.animation.Play("Attack");
var hit: RaycastHit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit)){
Distance = hit.distance;
if(Distance < maxDistance ){
hit.transform.SendMessage("ApplyDamage", theDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Where line 11 is: TheMace.animation.Play("Attack");
I have done everything as it shoud. Here is a screenshot of my workspace:
![1]
Where:
- is the Melee - you can see that the Mace is a child of it.
- the Melee script.
- TheMace variable is assigned correctly.
I know that I miss a small part here, but as a complete beginner, I just can not spot it. Can you give me a push?