Game Development Reference
In-Depth Information
Planning behaviors
Behaviors are just a fancy way of saying things or interactions that will happen in the
game . Breaking down these actions or reactions in this way helps to componentize how we
think our game will work. Stopping and thinking about this from the very beginning means
we won't get too many surprises later on. (There are always surprises after a good night's
sleep.)
For example, behaviors can take the following forms:
• Attacking another entity
• Taking damage
• Collecting the loot, which could be money or items
• Teleporting to another land
It is also important to note that visual effects as the result of a behavior or action are differ-
ent to those that affect the characteristics of the game's object. You may have a visual rep-
resentation as the result of a behavior or action (for example, a particle effect when taking
damage or the character swinging their sword to attack), but in Unity especially, you have
to keep these separate. We will cover more on this later.
Note
In traditional games that are built using other systems, bundling visual interactions or audio
with behaviors is quite common. However, Unity forces you to think differently; it recom-
mends you to work with the system, not against it.
Behaviors on classes should only affect the class that it is defined on. If you are going to af-
fect another class's attributes, it should be through another behavior on that class.
It is far too easy to simply perform player.health = 10 rather than play-
er.damage(10) ; this way any side effects or saves from damage can be taken into ac-
count within the class itself. Read on!
Search WWH ::




Custom Search