This script class has one private property. Since it is private, it can only be changed by methods. Its initial value is 1.0 – in other words, 100% health:
- health (float): The valid range is from 0 (dead!) to 1.0 (100% health).
There are three public methods:
- GetHealth(): This returns the current value of the health float number (which should be between 0 and 1.0).
- AddHealth(float): This takes a float as input (the amount to add to the health) and returns a Boolean true/false regarding whether the value was valid. Note that the logic of this method is that it accepts values of 0 or more (and will return true), but it will ensure that the value of health is never more than 1.
- KillCharacter(): This method sets health to zero and returns true since it is always successful in this action.