In this recipe, we will combine many different kinds of tests for a feature tha's included in many games – a visual health bar representing the player's numeric health value (in this case, a float number from 0.0 to 1.0). Although far from comprehensively testing all the aspects of the health bar, this recipe will provide a good example of how we can go about testing many different parts of a game using the Unity Testing tools.
A Unity package has been provided that contains the following:
- Player.cs: A player script class for managing values for player health that uses delegates and events to publish health changes to any listening View classes.
- Two View classes that register to listen for player health change events:
- HealthBarDisplay.cs: This updates fillAmount for a UI Image for each new player health value that's received.
- HealthChangeLogger.cs: This prints messages about...