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:
In the Project panel, scroll down until the
PACKT_Scripts
folder is visible.Double-click on it to make its contents visible in the Assets panel.
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 a boolean. It is basically an on/off switch that will allow the zombie to go into a new routine.
The next two variables deal with the sound that we will be using to make it clear that the zombie has been alerted.
The snarlSound
variable is an audio clip...