1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| using System.Collections;
public class Health : MonoBehaviour {
public float MaxHealth=100;
public float CurrentHealth;
public bool Invincible;
public bool Dead;
// Use this for initialization
void Start () {
//MAKE THE CURRENT HEALTH THE MAX HEALTH AT START
CurrentHealth=MaxHealth;
}
// Update is called once per frame
void Update () {
//IF INVINCIBLE, HE CANNOT DIE..
if(Invincible){
CurrentHealth=MaxHealth;
}
else{
if(CurrentHealth<=0){
CurrentHealth=0;
Dead=true;
}
//MAX HEALTH
if(CurrentHealth>=MaxHealth)CurrentHealth=MaxHealth;
//WHEN DEATH IS UPON HIM
if(Dead){
//TELL THE AI SCRIPT HE IS DEAD
FreeAI AI=(FreeAI)GetComponent("FreeAI");
if(AI){
if(AI.IsDead){}
else AI.IsDead=true;
}
}
}
}
}
|