Game Development Reference
In-Depth Information
Figure 7-7. Configuring the Drone enemy with a Billboard component and a BoxCollider component
Tip
Billboard and Box Collider objects were considered in depth for power-up objects in Chapter 4.
Coding Enemy Damage
The preliminaries taken so far have established the basics for the Drone prefab, but lots more awaits
us in terms of C# coding. Let's start by considering the issue of dealing damage to the Enemy.
When the Player fires a weapon at an Enemy that's in range, the Enemy should take damage unless
there's an overriding reason not to (such as an invincibility shield), and further, the Enemy should
be destroyed if the dealt damage reduces its health to 0 or below. In this game, we won't need to
consider invincibility shields and other damage-reducing factors. I mention it here primarily because
for many games it is a consideration. To implement the damage receiving functionality for the Drone,
as well as its other behaviors, we'll code two classes, and we'll use the object-oriented concept of
class inheritance to make them work together. Inheritance was introduced in the previous chapter
when considering weapon implementation. I'll call these classes Enemy (the base class for all
Enemies generally), and Enemy_Drone (the derived class implementing Drone-specific functionality).
These classes will be added in the C# script files Enemy.cs and Enemy_Drone.cs , respectively. Go
ahead and add these script files now, as shown in Figure 7-8 .
 
Search WWH ::




Custom Search