Munchy2007

Unet5Tut6Pt2HUD

Feb 28th, 2016
6,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class HUD : MonoBehaviour {
  6.     public static HUD instance;
  7.     Text healthText;
  8.     Text scoreText;
  9.  
  10.     void Awake () {
  11.         if(instance == null)
  12.         {
  13.             instance = this;
  14.             healthText = transform.Find("HealthText").GetComponent<Text>();
  15.             scoreText = transform.Find("ScoreText").GetComponent<Text>();
  16.             GetComponentInChildren<Camera>().gameObject.SetActive(false);
  17.         }
  18.         else
  19.         {
  20.             DestroyImmediate(gameObject);
  21.             return;
  22.         }
  23.     }
  24.  
  25.     public void DisplayHealth(int health)
  26.     {
  27.         healthText.text = string.Format("Health: {0}", health);
  28.     }
  29.  
  30.     public void DisplayScore(int score)
  31.     {
  32.         scoreText.text = string.Format("Score: {0}", score);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment