59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class states : MonoBehaviour
|
||
|
{
|
||
|
public bool isDead = false;
|
||
|
public float MaxHP = 100;
|
||
|
float myHP = 100;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
myHP = MaxHP;
|
||
|
}
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
}
|
||
|
private void detactDeath()
|
||
|
{
|
||
|
if (myHP <= 0)
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
isDead = true;
|
||
|
}
|
||
|
}
|
||
|
// while got hit
|
||
|
public void ReactToHit(float Damage, GameObject damageSource)
|
||
|
{
|
||
|
myHP -= Damage;
|
||
|
Debug.Log("HP:" + myHP);
|
||
|
if (myHP <= 0)
|
||
|
{
|
||
|
if (damageSource.tag == "Player")
|
||
|
{
|
||
|
damageSource.GetComponent<AgentWithGun>().killRecord(transform.position);
|
||
|
Destroy(this.gameObject);
|
||
|
isDead = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
isDead = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// get my hp from other script
|
||
|
public float getnowHP()
|
||
|
{
|
||
|
return myHP;
|
||
|
}
|
||
|
|
||
|
public void destroyMe()
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
isDead = true;
|
||
|
}
|
||
|
}
|