Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4.  
  5. public class HealthSystem : MonoBehaviour{
  6.  
  7. //Stats
  8. public int Deaths;
  9.  
  10. //Public
  11. public GameObject Player = null;
  12. public float Health;
  13. public float maxHealth;
  14. public float RespawnTime;
  15. public GameObject SpawnPoint = null;
  16.  
  17. //Private
  18. private bool Working;
  19. private bool isDead;
  20.  
  21. void Start(){ Health = maxHealth; if(Player != null){Working = false;}if(Player != null && SpawnPoint != null){Working = true;}isDead = false;}
  22.  
  23. void Update(){
  24. this.GetComponent<HealthBar> ().maxProgress = maxHealth;
  25. this.GetComponent<HealthBar> ().Progress = Health;
  26.  
  27. if(Working){
  28. if(Health > maxHealth){Health = maxHealth;}
  29. if(Health <= 0){Respawn ();}
  30. }else{DebugText("Missing_Variable");}}
  31.  
  32. void Respawn(){isDead = true; Deaths++; Player.SetActive(false); Health = maxHealth; Debug.Log("Died"); DeathRespawn(); Player.SetActive(true); Player.transform.position = SpawnPoint.transform.position;}
  33.  
  34. private IEnumerator DeathRespawn(){ yield return new WaitForSeconds(RespawnTime);}
  35.  
  36. void DebugText(string Info){
  37. switch(Info){
  38. case "Missing_Variable":
  39. Debug.Log("A variable/ variables are empty.");
  40. break;
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement