using UnityEngine; using System.Collections; public class GUIGame : MonoBehaviour { #region PUBLIC VARIABLES public GameObject heart1; // GameObject that contains the left-most heart element of the GUI public GameObject heart2; // GameObject that contains the center heart element of the GUI public GameObject heart3; // GameObject that contains the right-most heart element of the GUI public Sprite heartFull; // The Sprite used to reflect a full heart public Sprite heartHalf; // The Sprite used to reflect a half heart public Sprite heartEmpty; // The Sprite used to reflect an empty heart #endregion #region GUI METHODS [UpdateHealth] /// /// Sets the GUI hearts to match the player's health value /// /// Health. public void UpdateHealth(int health) { switch(health) { case 0: // Player has no health heart1.GetComponent().sprite = this.heartEmpty; heart2.GetComponent().sprite = this.heartEmpty; heart3.GetComponent().sprite = this.heartEmpty; break; case 1: // Player has 0.5 hearts heart1.GetComponent().sprite = this.heartHalf; heart2.GetComponent().sprite = this.heartEmpty; heart3.GetComponent().sprite = this.heartEmpty; break; case 2: // Player has 1 heart heart1.GetComponent().sprite = this.heartFull; heart2.GetComponent().sprite = this.heartEmpty; heart3.GetComponent().sprite = this.heartEmpty; break; case 3: // Player has 1.5 hearts heart1.GetComponent().sprite = this.heartFull; heart2.GetComponent().sprite = this.heartHalf; heart3.GetComponent().sprite = this.heartEmpty; break; case 4: // Player has 2 hearts heart1.GetComponent().sprite = this.heartFull; heart2.GetComponent().sprite = this.heartFull; heart3.GetComponent().sprite = this.heartEmpty; break; case 5: // Player has 2.5 hearts heart1.GetComponent().sprite = this.heartFull; heart2.GetComponent().sprite = this.heartFull; heart3.GetComponent().sprite = this.heartHalf; break; case 6: // Player has 3 hearts heart1.GetComponent().sprite = this.heartFull; heart2.GetComponent().sprite = this.heartFull; heart3.GetComponent().sprite = this.heartFull; break; } } #endregion }