There is no 'Animation' attached to the "Main Camera" game object, but a script is trying to access.

Hello there,

I was wondering if anyone could help me:
My error is:

“MissingComponentException: There is no ‘Animation’ attached to the “Main Camera” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “Main Camera”. 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:12)”

This is my code:

#pragma strict

var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update ()
{
        if (Input.GetButtonDown("Fire1"))
        {
        animation.Play("attackArbiter");
        var hit : RaycastHit;
        if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
        {
            Distance = hit.distance;
            if (Distance < MaxDistance)
            {
            hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
        }
        }
        }
}

Here is an image of the component attached to the game object arbiter

Could anyone tell me whats wrong, I’ve been writing in lua for the past year on corona and want to make this change happen.

Thank you
James

You probably added the script to the wrong game object. Select the error message in the console. This will highlight the game object containing the script that is responsible for the error message.
It seems you have attached it to the “MainCamera” instead of the “arbiter” game object.

This is the img of the error. As you can see there is no component added to the main camera for the animation.
Is there anything else it could be or have I made a stupid mistake/assumption?

Thank you for helping,
James

At line number 10, you are calling animation.Play (…). This only works if there is an animation component. As the arbiter game object contains an animation component, I assume you want to instead play the animation of that one.

So what would the code be?

Thanks,
James

This may be useful:
https://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent