Reputation: 744
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:
Where:
1) is the Melee - you can see that the Mace is a child of it. 2) the Melee script. 3) 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?
EDIT: inspector screenshot:
Upvotes: 1
Views: 657
Reputation: 2618
Your object has an Animator
component attached. It needs to have an Animation
component instead.
Animator
is used for manipulating Mecanim animations. Animation
is used for playing back legacy animation clips that are imported with the model.
Upvotes: 2