Game Development Reference
In-Depth Information
When the script is attached to the player, it is possible to set the initial value of health through
initialHealth . However, the script ensures that the actual start value is between maxHealth
and 1. This prevents initial health from exceeding set limits as well as preventing player
from starting dead. Player's death occurs when the value of the internal state health gets
less than or equal to 0. This internal state can be altered only through IncreaseHealth() and
DecreaseHealth() functions. These functions enforce minimum and maximum limits and
send relevant messages upon each health state change. When the player dies, the script
sends OnPlayerDeath message.
PlayerHealth gives us the ability to manage player's health and detect his death. In addition
to that, it allows us to change health value by calling appropriate functions. It does not,
however, say anything about what causes the health to increase/decrease. Therefore, we
need another script which can detect hits that player receives and consequently decreases
health. This script is PainfulDamageTaker , shown in Listing 75.
Listing 75: A script to receive painful hit and consequently reduce player's health
Search WWH ::




Custom Search