Guest User

Untitled

a guest
Jun 8th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. sing 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. private LifeManager lifeSystem;
  18.  
  19. // Use this for initialization
  20. void Start () {
  21. text = GetComponent<Text>();
  22.  
  23. playerHealth = maxPlayerHealth;
  24.  
  25. levelManager = FindObjectOfType<LevelManager>();
  26.  
  27. lifeSystem = FindObjectOfType<LifeManager>();
  28.  
  29. isDead = false;
  30. }
  31.  
  32. // Update is called once per frame
  33. void Update () {
  34. if(playerHealth <= 0 && !isDead)
  35. {
  36. playerHealth = 0;
  37. levelManager.RespawnPlayer();
  38. lifeSystem.TakeLife();
  39. isDead = true;
  40. }
  41.  
  42. text.text = "" + playerHealth;
  43.  
  44. }
  45.  
  46. public static void HurtPlayer(int damageToGive)
  47. {
  48. playerHealth -= damageToGive;
  49. }
  50.  
  51. public void FullHealth()
  52. {
  53. playerHealth = maxPlayerHealth;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment