Game Development Reference
In-Depth Information
25 //Strike - called each time the enemy makes a strike against the player (deal damage)
26 public void Strike()
27 {
28 //Damage player
29 PC.gameObject.SendMessage("ApplyDamage", AttackDamage,
SendMessageOptions.DontRequireReceiver);
30 }
31 //------------------------------------------------
Lines 26-30 . The most noteworthy functionality for the Enemy_Drone here
concerns the attacking functionality. Here, the Strike function is called from
the base class Enemy to implement damage-dealing to the Player. To achieve
this, the Enemy invokes the ApplyDamage function on the Player, which both
deals damage and plays the red-flash animation (created in Chapter 5 using
procedural textures).
Let's now apply these code changes and take CMOD for a test run to see the complete FSM for the
enemy Drone character in action. On pressing Play, you'll have an Enemy that patrols, chases, and
attacks! As a gamer, it can be difficult to observe the Patrol state fully with the complete FSM. This is
because, typically, the Enemy will see and chase the Player whenever the Player enters the Enemy's
line of sight. So, if you can see the Enemy in-game, he's probably already in the Chase or Attack
state—coming to get you. But Unity makes it easy to test functionality for all states, by observing
out-of-sight enemy movements in the Scene viewport, as opposed to the Game viewport. You can
align the viewports side by side and debug as much as you need (see Figure 7-18 ).
Figure 7-18. Testing Enemy AI. Using a split screen view, between the Scene and Game viewports, to observe enemy movement
in all three states
Search WWH ::




Custom Search