Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- public class HealthSystem : MonoBehaviour{
- //Stats
- public int Deaths;
- //Public
- public GameObject Player = null;
- public float Health;
- public float maxHealth;
- public float RespawnTime;
- public GameObject SpawnPoint = null;
- //Private
- private bool Working;
- private bool isDead;
- void Start(){ Health = maxHealth; if(Player != null){Working = false;}if(Player != null && SpawnPoint != null){Working = true;}isDead = false;}
- void Update(){
- this.GetComponent<HealthBar> ().maxProgress = maxHealth;
- this.GetComponent<HealthBar> ().Progress = Health;
- if(Working){
- if(Health > maxHealth){Health = maxHealth;}
- if(Health <= 0){Respawn ();}
- }else{DebugText("Missing_Variable");}}
- void Respawn(){isDead = true; Deaths++; Player.SetActive(false); Health = maxHealth; Debug.Log("Died"); DeathRespawn(); Player.SetActive(true); Player.transform.position = SpawnPoint.transform.position;}
- private IEnumerator DeathRespawn(){ yield return new WaitForSeconds(RespawnTime);}
- void DebugText(string Info){
- switch(Info){
- case "Missing_Variable":
- Debug.Log("A variable/ variables are empty.");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement