Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to animate object.

Discussion in 'Scripting' started by Epic-Username, Jul 15, 2015.

  1. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    I have an object with a animation component and i have this script attached to it and i need to know how to i play an animation through a script. I have never animated a object before so i don't know what to do i have watched this https://unity3d.com/learn/tutorials/modules/beginner/animation/animator-component but i would prefer to animate the object through a script so whats the code to animate objects and how would i stop, play, loop and increase speed of the animation.
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Animator.Play?
    Animator.Stop?

    Check out the scripting reference on the Animator component and you'll see all the functions.
     
  3. SkillBased

    SkillBased

    Joined:
    Aug 11, 2014
    Posts:
    141
    I could be wrong but I believe animating through script by directly accessing the Animation is considered "legacy" while the Animator is the "new" way of doing things.

    That isn't an argument in and of itself but the Animator really is quite powerful in handling states and by holding a reference to your Animator component you can still control it via script. Perhaps its a good idea to look at it more closely and consider not directly accessing the animation clips.
     
  4. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    I don't know how to use the animator though.
     
  5. MilanGM

    MilanGM

    Joined:
    Nov 20, 2013
    Posts:
    8
    I am also having troubles with animating objects. As far as I figured it out, you play animations using Animator component, not the Animation component.
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  7. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339

    Ok thanks i'll start using the new way but can you help me over at this question: http://forum.unity3d.com/threads/how-do-i-get-position-and-rotation-of-an-animated-object.341316/