Advertisement
Guest User

Untitled

a guest
Jun 5th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class HealthManager : MonoBehaviour {
  6.  
  7. public int maxPlayerHealth;
  8.  
  9. public static int playerHealth;
  10.  
  11. Text text;
  12.  
  13. private LevelManager levelManager;
  14.  
  15. public bool isDead;
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. text = GetComponent<Text>();
  20.  
  21. playerHealth = maxPlayerHealth;
  22.  
  23. levelManager = FindObjectOfType<LevelManager>();
  24. isDead = false;
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update () {
  29. if(playerHealth <= 0 && !isDead)
  30. {
  31. playerHealth = 0;
  32. levelManager.RespawnPlayer();
  33. isDead = true;
  34. }
  35.  
  36. text.text = "" + playerHealth;
  37.  
  38. }
  39.  
  40. public static void HurtPlayer(int damageToGive)
  41. {
  42. playerHealth -= damageToGive;
  43. }
  44.  
  45. public void FullHealth()
  46. {
  47. playerHealth = maxPlayerHealth;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement