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 waveform of a sound clip to animate objects in the scene


In this recipe, we will use a waveform of a sound effect to create motion based on the average volume of the fragment of the waveform.

Getting ready

To follow this recipe, we need a sound effect. You can use the provided example Unity project and go to the Chapter 07 Special effects\Recipe 09 Using waveform of a sound clip to animate objects in the scene directory. If you open the Example.unity scene there and play the game, you will be able to see a few cubes react to the playing audio clip.

How to do it...

To use sound waveforms for animation, follow these steps:

  1. Import the sound into Unity.
  2. Create an empty game object and name it AudioSource.
  3. Add an Audio Source component to it, and make the sound Loop and Play On Awake. Drag and drop your sound into the AudioClip field.
  4. Create a Cube game object (go to Game Object3D ObjectCube).
  5. Create a new script and call it ScaleWithWaveForm.cs. In this script, we have one public AudioSource...