Game Development Reference
In-Depth Information
Figure 8-14. Previewing a GUI label in real time
Right now, the root GUI object features two label components that each display default static text for
both the ammo status and health status. This text currently never changes throughout gameplay, as
it is. So we'll need to code extra functionality in the GUIUpdateStats class to update the label text on
each frame, displaying the latest Player health and ammo status as the game unfolds. The C# code
for this class is given in Listing 8-7. This class should also be added as a component to the root GUI
object, alongside the labels.
Listing 8-7. GUIUpdateStats.cs: Class for Updating GUI Text with Health and Ammo Status
01 //--------------------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 //--------------------------------------------------------------
05 public class GUIUpdateStats : MonoBehaviour
06 {
07 //Player reference
08 private PlayerController PC = null;
09
10 //Health Label Component
11 public GUILabel HealthLabel = null;
12
13 //Ammo Label Component
14 public GUILabel AmmoLabel = null;
15
 
Search WWH ::




Custom Search