O'Reilly logo

Unity Character Animation with Mecanim by Jamie Dean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding code to the zombie_ready script

The script currently attached to the female zombie, adequately handles its current states: Idle and Walk. We need to add a few lines of code to the script to trigger the face animation:

  1. In the Project panel, scroll down until the PACKT_Scripts folder is visible.
  2. Double-click on it to make its contents visible in the Assets panel.
  3. Locate zombie_ready and double-click on it to open the script in MonoDevelop.

We will start by adding a few variables. At the top of the script, add the following lines of code:

var target : Transform;
var alerted : boolean = false;
var snarlSound : AudioClip;
var soundReady : boolean = true;

The target variable will store the player character's position. The next variable, alerted is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required