Search Unity

Playing animation?

Discussion in 'Animation' started by Denisowator, May 23, 2017.

  1. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    First off, let me just say that animation is the aspect of game development that I work on the least, in all my time of using Unity or any other game creation system.

    I have already looked at the Unity Manual, multiple videos on YouTube, and on old posts and threads on the "Forums" and "Answers".

    I always have trouble remembering the basics (like how to play an animation from a script), despite all the years of experience.

    Currently this is what I have:
    Code (CSharp):
    1. public Animation Effect1; //above all methods
    2.  
    3. Effect1.Play(); //in the Update method
    I'm having a feeling I need to make a component reference, but I'm not 100% sure.

    Keep in mind I'm not planning on using a Animator for this, and I just want to call an animation.

    I'm getting a warning saying "
    The AnimationClip 'Effect1' used by the Animation component 'EffectCamera' must be marked as Legacy.
    ", and the animation doesn't play.

    P.S. The script is attached to the object that is supposed to be playing the animations.


    UPDATE: I've been searching around for the past hour, and I still haven't found anything that works. Even following up-to-date youtube tutorials line for line, doesn't work. I just either get errors I don't understand and can't find a fix to, or there's just a warning and the animation doesn't play.

    UPDATE 2: I've been trying to do this by creating Animator Controller transitions, and settings their booleans in the script, but that doesn't seem to be working either. I've set everything up correctly, it's just the code that isn't working.
     
    Last edited: May 23, 2017
  2. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    I figured it out for doing it through the Animator Controller. I just needed to set Effect1 to...
    Code (CSharp):
    1. GetComponent<Animator> ();
    I think that's the main reason I forgot how to do it. Because I don't understand why you have to give the variable an Animator reference, if you already gave it the variable type "Animator" (especially if it's in the same object as the animator). That's what I can never get my head around.
     
    Last edited: May 24, 2017