Advertisement
Placido_GDD

Drone Health

Nov 15th, 2021
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DroneHealth : MonoBehaviour
  6. {
  7.        public float Health;
  8.        public bool isDead;
  9.        public DroneManager droneManage;
  10.        GameObject thisGameObj;
  11.        //use for initialization
  12.        public void Start()
  13.        {
  14.            isDead = false;
  15.            thisGameObj = this.gameObject;
  16.        }
  17.        
  18.        public void Update()
  19.        {
  20.                if(Health <= 0)
  21.                {
  22.                    isDead = true;
  23.                    //Remove from Drone Manager List
  24.                    droneManage.drones.Remove(thisGameObj);
  25.                    //Destroy this GameObject
  26.                    Destroy(this.gameObject);
  27.                }
  28.        }
  29.        public void Damage(float dmgVal)
  30.        {
  31.             if(isDead == false)
  32.                    {
  33.                     Health = Health - dmgVal;
  34.                    }           
  35.        }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement