Animate a GameObject with the Animation component
Instructions on how to use the Animation component to animate a GameObject.
Read time 2 minutesLast updated 13 days ago
Use the Animation component to add animations to a GameObject and its children in your scene. To set up animations on your objects:
Add an Animation component to a GameObject
To animate your GameObject, your object needs an Animation component. To add an Animation component:- Select the GameObject you want to animate in your scene.
- Open the Inspector Panel.
- Select Add Component and choose Animation.
Assign an animation clip
Add an animation clip to your Animation component to change your object's properties or movements over time:- If your GameObject doesn't contain an Animation component, Add an Animation component to a GameObject.
- In the Animation component, select Add (+).
- Unity Studio creates an animation clip for your object and opens the Animation Timeline window.
- If you want to use the new animation clip, edit it in the timeline.
- To use a different clip, select the circle icon next to the Animation field and choose your preferred clip.
Create an animation
To work with your animation on a timeline:- Move the cursor on the timeline to the moment you want to set a keyframe.
- Make a change to your GameObject. A keyframe is automatically created.
- Drag keyframes on the timeline to adjust the timing and duration of your animation. Move a keyframe onto another keyframe to merge them. You can select multiple keyframes by holding left-click and dragging a selection box around them. When in multi-select mode, keyframes can't be merged.
- Add more keyframes to create longer or more detailed animations. You can delete a keyframe by selecting it and pressing the Delete key on your keyboard.
- Press the Play button in the Animation Timeline window to preview your animation.
Examples
Use case | Description |
|---|---|
| Visual effects | Change the material color to create effects, like a blinking or pulsing object. |
| Trigger animations with Logic scripts | Use Logic to play, pause, or stop animations at specific moments in your application. For example, you might play an animation when a certain event happens. |
| Trigger animations with Button On Click | Set up a button to trigger an animation directly when the user clicks it. In the button's settings, add an action under When the button is clicked, select the GameObject, and choose the animation to play, pause, or stop. For more information, refer to Button. |