Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

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

Discussion in 'Animation' started by Jamesmallon1, Nov 25, 2014.

  1. Jamesmallon1

    Jamesmallon1

    Joined:
    Mar 30, 2014
    Posts:
    3
    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:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var TheDammage : int = 50;
    4. var Distance : float;
    5. var MaxDistance : float = 1.5;
    6. function Update ()
    7. {
    8.         if (Input.GetButtonDown("Fire1"))
    9.         {
    10.         animation.Play("attackArbiter");
    11.         var hit : RaycastHit;
    12.         if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
    13.         {
    14.             Distance = hit.distance;
    15.             if (Distance < MaxDistance)
    16.             {
    17.             hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
    18.         }
    19.         }
    20.         }
    21. }
    22.  
    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
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    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.
     
  3. Jamesmallon1

    Jamesmallon1

    Joined:
    Mar 30, 2014
    Posts:
    3


    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
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    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.
     
  5. Jamesmallon1

    Jamesmallon1

    Joined:
    Mar 30, 2014
    Posts:
    3
    So what would the code be?

    Thanks,
    James
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667