Game Development Reference
In-Depth Information
Chapter
6
Weapons
Let's quickly recap what we've done so far in CMOD. At this stage, we've created a complete
game environment with rooms and corridors, collectable power-up objects for health restore and
cash bonuses, a notifications manager class to send and dispatch events to game objects, and
a universal player controller for desktops and mobiles, including first-person functionality with a
complementary head bob. In this chapter, we'll build on this existing work by adding weapons for
the Player character—specifically, a short-range fists/punch weapon (the default weapon) and a
long-range gun weapon, which can be collected through a weapons power-up. The purpose of these
weapons is to damage Enemy characters. Of course,
right now
, we haven't created any enemies for
CMOD—they'll be coded in the
next
chapter. But here we'll at least make a start with weapons.
In creating these, a wide range of Unity and C# concepts will be explored in depth; specifically, sprite
and object animation, physics and rays,
object orientation
,
class inheritance
and
polymorphism
.
So let's get started . . .
Weapons Overview
CMOD features a total of two weapons that can be used by the Player character; though only one
weapon may be active and in use at any one time. These weapons are
fists that punch
(as shown in
Figure
6-1
) and a
gun
(as shown in Figure
6-2
). These weapons are considered in more detail next.
Figure 6-1.
The default fists/punch weapon
179