Book Image

Unity 5.x Animation Cookbook

By : Maciej Szczesnik
Book Image

Unity 5.x Animation Cookbook

By: Maciej Szczesnik

Overview of this book

This recipe-based practical guide will show you how to unleash the power of animation in Unity 5.x and make your games visually impeccable. Our primary focus is on showing you tools and techniques to animate not only humanoid biped characters, but also other elements. This includes non-humanoid character animation, game world creation, UI element animation, and other key features such as opening doors, changing lights, transitioning to different scenes, using physics, setting up ragdolls, creating destructible objects and more. While discussing these topics, the book will focus on mecanim, the Unity 3D animation tool, and how you can use it to perform all these tasks efficiently and quickly. It contains a downloadable Unity project with interactive examples for all the recipes. By the end of this book, you will be confident and self-sufficient in animating your Unity 3D games efficiently.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using the Rotate() function to animate an object


In this recipe, we will use the Transform.Rotate() function to create an infinite looping animation of a windmill. We could make the same with the Animation View, but sometimes writing a simple script means much less effort than creating a key frame animation.

Getting ready

We need a few models we can rotate in this recipe. As an example, we will use a windmill. It is composed of three game objects: WindmillBase, which is the root of the whole windmill, Windmill which is parented to the WindmillBase, and WindmillWings which is parented to the Windmill. The Windmill game object itself can rotate in the Y axis. The WindmillWings game object can rotate in its local Z axis.

Windmill hierarchy

You can download the example project and go to the Chapter 10 Miscellaneous\Recipe 03 Using the Rotate function to animate an object directory. Open the Example.unity scene there and play the game. You will see the windmill rotating around the Y axis and its...