Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Health : MonoBehaviour {
- public float health = 100;
- public bool Invincible;
- public bool alive;
- public bool canRespawn;
- Animator anim;
- public AudioClip hurtSFX;
- public GameObject DeathScreenUI;
- // Use this for initialization
- void Start () {
- anim = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update () {
- if (health < 1)
- {
- alive = false;
- anim.SetBool("Dead", true);
- }
- else {
- alive = true;
- anim.SetBool("Dead", false);
- }
- if (canRespawn)
- {
- if (!alive)
- {
- Invoke("Respawn", 5f);
- }
- else
- {
- CancelInvoke();
- }
- }
- if (this.GetComponent<PhotonView>()) {
- if (this.GetComponent<PhotonView>().isMine)
- {
- if (health < 1)
- {
- DeathScreenUI.SetActive(true);
- }
- else {
- DeathScreenUI.SetActive(false);
- }
- }
- }
- }
- [PunRPC]
- public void Takedamage(float damage) {
- if (!Invincible)
- {
- health = health - damage;
- AudioSource.PlayClipAtPoint(hurtSFX, transform.position, 0.7f);
- }
- }
- [PunRPC]
- public void TakedamageReact()
- {
- if (!Invincible)
- {
- if (anim.GetFloat("BZWep") == 0)
- {
- anim.SetTrigger("Hurt");
- }
- }
- }
- void Respawn() {
- anim.SetTrigger("Reset");
- health = 100;
- }
- [PunRPC]
- public void HealthGenerate()
- {
- if (health < 70)
- {
- health += Time.deltaTime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement