public class Health : MonoBehaviour {
public float curHealth;
public float maxHealth;
public bool enemyDied = false;
personal Animator anim;
public Slider healthBar;
`enter code right here` personal ThirdPersonCharacter thirdPerson;
personal void Start()
{
curHealth = maxHealth;
healthBar.minValue = 0;
healthBar.worth = curHealth;
healthBar.maxValue = maxHealth;
anim = GetComponent<Animator>();
thirdPerson = GetComponent<ThirdPersonCharacter>();
}
void Update()
{
float hit = anim.GetFloat("hit");
if (hit > 0)
{
hit -= Time.deltaTime * 3;
anim.SetFloat("hit", hit);
}
if (curHealth < 1)
{
Physics.SyncTransforms();
anim.SetBool("death", true);
}
if (Input.GetKeyUp(KeyCode.Space))
{
SendDamage(Random.Range(10, 20));
}
}
public void SendDamage(float damageValue)
{
curHealth -= damageValue;
healthBar.worth = curHealth;
if (curHealth <= 0)
{
enemyDied = true;
}
Invoke(nameof(Resurrect), 2f);
anim.SetFloat("hit", 1);
}
public void Resurrect()
{
SpriteRenderer blackout = Camera.important.remodel.GetComponentInChildren<SpriteRenderer>();
Color orjinalRenkWasted = blackout.shade;
Color clrWhitealpha0 = new Color(1, 1, 1, 1);
Color clr = new Color(0, 0, 0, 1);
blackout.remodel.GetChild(0).GetComponent<SpriteRenderer>().DOColor(clr, .5f).SetDelay(2f).OnStart(() =>
{
blackout.DOColor(clrWhitealpha0, .5f).SetDelay(.5f).OnComplete(() =>
{
Invoke(nameof(BringEverythingBack), 2f);
blackout.remodel.GetChild(0).GetComponent<SpriteRenderer>().DOColor(new Color(0, 0, 0, 0), .5f).SetDelay(2.5f).OnStart(() =>
{
blackout.DOColor(orjinalRenkWasted, .25f);
});
});
});
}
void BringEverythingBack()
{
remodel.root.place = GameObject.FindGameObjectWithTag("Respawn").remodel.place;
}