Create Health and Ragdoll component and and them to enemy

This commit is contained in:
2024-08-09 17:36:09 +02:00
parent 01c6f898f3
commit f3623c6036
6 changed files with 146 additions and 2 deletions

View File

@@ -0,0 +1,54 @@
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class HealthComponent : MonoBehaviour
{
[ReadOnly]
[SerializeField]
private int health;
[ReadOnly]
[SerializeField]
private bool isDead;
public UnityEvent onDied;
[Button]
public void Setup()
{
health = 100;
isDead = false;
}
public void TakeDamage(int damage)
{
health -= damage;
if (health < 0)
{
health = 0;
}
if (health == 0)
{
isDead = true;
onDied.Invoke();
}
}
[Button]
private void Take10Damage()
{
TakeDamage(10);
}
[Button]
private void Kill()
{
TakeDamage(health);
}
}