Game Development Reference
In-Depth Information
Building an interactive object
With these requirements in mind, let's build the framework for an interactive object
that can be collected by the player.
Implementing the CustomGameObj script
We will begin with the CustomGameObj class. This class allows us to specify how an
interactive object will behave when placed in the inventory, by giving it a unique type
that is relevant for our game. Create the script by performing the following steps:
1. Start from the codebase built in Chapter 1 , Introduction to E-Learning and the
Three Cs of 3D Games , to create a new subfolder in the assets folder named
Chapter 2 .
2. Using the new script wizard, right-click on it and create a new C# script named
CustomGameObject .
3. We will also add a public enumerated type to this class called CustomOb-
jectType . If you recall, an enumeration is just a list of identifiers of the in-
teger type that share a common logical relationship with one another, such as
the types of an object! Not only will this make discerning the type of this object
easy to read in the code, but it also serves as an interface to describe the clas-
sification of this object. We will use this information to determine some custom
rules while adding GameObjects to the inventory. To begin, we will start with
a few different types of objects, where an object of the Coin type will accu-
mulate in the same slot in the inventory. This holds true for objects of the type
Ruby , Diamond , and so on as well. Unique objects will be added in their own
slot in InventoryMgr as follows:
Public enum CustomObjectType
{
Invalid = -1,
Unique = 0,
Coin = 1,
Ruby = 2,
Emerald = 3,
Diamond = 4
Search WWH ::




Custom Search