2022-11-28 22:54:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
public class States : MonoBehaviour
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
public bool isDead = false;
|
2023-06-30 09:30:12 +00:00
|
|
|
public float maxHP = 100;
|
|
|
|
private float myHP = 100;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
private void Start()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-06-30 09:30:12 +00:00
|
|
|
myHP = maxHP;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
private void Update()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
|
|
|
|
private void DetactDeath()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
if (myHP <= 0)
|
|
|
|
{
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
isDead = true;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
// while got hit
|
|
|
|
public void ReactToHit(float Damage, GameObject damageSource)
|
|
|
|
{
|
|
|
|
myHP -= Damage;
|
|
|
|
Debug.Log("HP:" + myHP);
|
|
|
|
if (myHP <= 0)
|
|
|
|
{
|
|
|
|
if (damageSource.tag == "Player")
|
|
|
|
{
|
2023-07-28 10:44:02 +00:00
|
|
|
damageSource.GetComponent<AgentController>().KillRecord(transform.position);
|
2022-11-28 22:54:08 +00:00
|
|
|
Destroy(this.gameObject);
|
|
|
|
isDead = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
isDead = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
// get my hp from other script
|
2023-06-30 09:30:12 +00:00
|
|
|
public float GetnowHP()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
return myHP;
|
|
|
|
}
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
public void DestroyMe()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
isDead = true;
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
}
|