Neues Projekt

This commit is contained in:
2026-05-20 19:47:36 +02:00
parent 01d76eccb1
commit 21aeb533c9
699 changed files with 19934 additions and 427294 deletions
+51
View File
@@ -0,0 +1,51 @@
using UnityEngine;
public class EnemyHealth : MonoBehaviour
{
[SerializeField] private int startingHealth = 3;
private int currentHealth;
private Animator anim;
private bool dead;
private void Awake()
{
currentHealth = startingHealth;
anim = GetComponent<Animator>();
}
public void TakeDamage(int damage)
{
if (dead) return;
currentHealth -= damage;
anim.SetTrigger("hurt");
if (currentHealth <= 0)
{
Die();
Debug.Log("Enemy is down");
}
}
private void Die()
{
dead = true;
anim.SetTrigger("die");
// Enemy deaktivieren
GetComponent<MeleeEnemy>().enabled = false;
// Collider ausschalten
GetComponent<Collider2D>().enabled = false;
// Optional: Rigidbody stoppen
Rigidbody2D rb = GetComponent<Rigidbody2D>();
if (rb != null)
rb.linearVelocity = Vector2.zero;
Destroy(gameObject, 1.5f);
}
}