Advertisement
iFrenzo

Untitled

Nov 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Health : MonoBehaviour {
  7.     public float health = 100;
  8.     public bool Invincible;
  9.     public bool alive;
  10.     public bool canRespawn;
  11.     Animator anim;
  12.     public AudioClip hurtSFX;
  13.     public GameObject DeathScreenUI;
  14.     // Use this for initialization
  15.     void Start () {
  16.         anim = GetComponent<Animator>();
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.         if (health < 1)
  22.         {
  23.             alive = false;
  24.             anim.SetBool("Dead", true);
  25.         }
  26.         else {
  27.             alive = true;
  28.             anim.SetBool("Dead", false);
  29.         }
  30.  
  31.         if (canRespawn)
  32.         {
  33.             if (!alive)
  34.             {
  35.                 Invoke("Respawn", 5f);
  36.             }
  37.             else
  38.             {
  39.                 CancelInvoke();
  40.             }
  41.         }
  42.  
  43.         if (this.GetComponent<PhotonView>()) {
  44.             if (this.GetComponent<PhotonView>().isMine)
  45.             {
  46.                 if (health < 1)
  47.                 {
  48.                     DeathScreenUI.SetActive(true);
  49.                 }
  50.                 else {
  51.                     DeathScreenUI.SetActive(false);
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     [PunRPC]
  58.     public void Takedamage(float damage) {
  59.         if (!Invincible)
  60.         {
  61.             health = health - damage;
  62.             AudioSource.PlayClipAtPoint(hurtSFX, transform.position, 0.7f);
  63.         }
  64.     }
  65.  
  66.     [PunRPC]
  67.     public void TakedamageReact()
  68.     {
  69.         if (!Invincible)
  70.         {
  71.             if (anim.GetFloat("BZWep") == 0)
  72.             {
  73.                 anim.SetTrigger("Hurt");
  74.             }
  75.         }
  76.     }
  77.  
  78.     void Respawn() {
  79.         anim.SetTrigger("Reset");
  80.         health = 100;
  81.     }
  82.  
  83.     [PunRPC]
  84.     public void HealthGenerate()
  85.     {
  86.         if (health < 70)
  87.         {
  88.             health += Time.deltaTime;
  89.         }
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement