At present, the player's health is saved in the script collisionDetection
; however, it is not represented on the screen. We will create a new script that displays a health bar symbolized by a rectangle in the top-left corner of the screen. Its length will be proportional to the player's health (that is, ranging from 0 to 100 percent), and the color will also vary accordingly. For example, it will be green when the health is between 67 percent and 100 percent, orange when the health is between 33 percent and 67 percent, and red when the health is between 0 percent and 33 percent. These visual cues will help the player to judge when it is time to look for and collect med packs. Follow these steps to display the health bar:
Create a new folder labeled
Scripts
by selecting Assets | chapter4.Create a new script (JavaScript) inside this folder, rename it
HealthBar
, and add the following code to it:private var currHealth : int = 45; private var currentColor:Texture2D;...