Game Development Reference
In-Depth Information
Figure 11-21. The condition for the Gnome armed-to-Gnome disarming transition
9.
Click Play in the preview to see the transition.
The Gnome disarming-to-Closed transition is already set to trigger on Exit Time, so it requires no
extra attention.
With the new conditions set, you can test the functionality manually through the Animator view.
1.
Click Play, and set the Laser layer's Weight to 1 .
The progress bar loops happily in the Closed state.
2.
Set the Armed parameter to on or true.
The hat opens and the laser is raised. The progress now loops through the armed state. Because of
the mask, the rest of the gnome is animated using the Base layer states.
3.
Click the Base Layer bar in the upper left of the Animator to view its progress.
4.
Click the Laser layer to return to it, and uncheck the Armed parameter.
5.
Watch as the progress heads up to the Gnome disarming state and then
down to the Closed state once the clip has finished.
6.
Stop Play mode.
You are probably thinking it would be pretty handy to be able to control the arming/disarming
sequence with a key press. You are also probably wondering how all of this ties together with the
scripting, so now is a good time to create a script to make use of Mecanim's functionality.
7.
In the Game Scripts folder, create a new C# script and name it
LaserController .
8.
Open it, and add the following variables beneath the class declaration:
Animator animator; // var to hold the animator component
In the Start function, add the following to assign the Animator component:
animator = GetComponent <Animator>(); // assign the object's animator component
9.
 
Search WWH ::




Custom Search