Create and Play animation in Unity

This article provides step by step guide to create and play animation in unity game engine.

Download Unity Package for Sample Project (Unity 5.6.1): AnimationDemo

Create Animation in Unity

  • Create a new project in unity and a cube game object in your scene. Your scene will look this below given image. I have scaled the cube object and changed its color but that is not mandatory.
    Create and Play animation in unity - Scene
  • Navigate to Windows -> Animation in unity editor. It will open the animation panel. You can adjust the position of this panel upon your requirement.Create and Play animation in unity - 1-2
  • Select cube game object in scene. A create button will appear on animation panel. Click on Create button to generate animation for selected game object.
    Create and Play animation in unity 1
  • On clicking the Create button, animation panel will show to add property for the animation.
    Create and Play animation in unity 2
  • Click on Add Property button. It will show you the list of properties that you can add in the animation.
    Create and Play animation in unity 3
  • For this tutorial, I am adding Position and Rotation properties. By default, you will get 60 consecutive samples, on which you can change values of these properties.
    Create and play animation - 4-5
    Details of marked numbers in above image:

    1. Recording: Hit this button if you want to record transformation or any other changes on the selected game object. See implementation in next step.
    2. Play: Play the recorded animation
    3. Samples: You can change the sample size here.
    4. Red Marker: change this marker position to add new values to the properties
    5. Sample time line: Place above marker to this sample values.

    You can drag and place the red line in sample time line to put your customized value for the animation. I am adding one stop point at 30th sample and changing the position and rotation values. Then again, I will do the same for 60th sample.
    Create and Play animation in unity 8
    Create and Play animation in unity 9

  • Alternatively, you can click on record button and transform you game object. This transformation will be recorded in an animation file that you can play later. If you will click on the recording button then you “Play, Pause and Stop” button will display in red color.
    Create and Play animation in unity 4
  • Click on play button in animation panel to see how animation play. Modify the values in animation panel if required.

Play Animation in Unity

  • The unity editor would have generated two files by now – animation and the animator controller. The animator component will be attached to the Cube game object.
    Create and Play animation in unity 9-10
  • By default, the animation will play in loop. Select CubeAnimation.anim and uncheck Loop Time property in inspector. Now the animation will play only once.
    Create and Play animation in unity 6
  • Open Cube.Controller. You will see CubeAnimation state over there will be the default state of the controller. It mans at runtime this state will be played automatically.
    Create and Play animation in unity 10
  • Now we can test our application. Hit the play button.
    Animation PlayThat’s it for this tutorial. Please post your comments for queries and feedback. Thanks for reading.
Share Button
The following two tabs change content below.
Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Latest posts by Gyanendu Shekhar (see all)

Gyanendu Shekhar

Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

2 thoughts on “Create and Play animation in Unity

Leave a Reply

Your email address will not be published. Required fields are marked *