You've already forked zumbi-game
29 lines
601 B
C#
29 lines
601 B
C#
using UnityEngine;
|
|
|
|
public class ZombieController : MonoBehaviour
|
|
{
|
|
[SerializeField] private float maxHealth = 100f;
|
|
private float currentHealth;
|
|
|
|
private void Start()
|
|
{
|
|
currentHealth = maxHealth;
|
|
}
|
|
|
|
public void TakeDamage(float amount)
|
|
{
|
|
currentHealth -= amount;
|
|
Debug.Log($"{gameObject.name} dostal {amount} damage. HP: {currentHealth}/{maxHealth}");
|
|
|
|
if (currentHealth <= 0)
|
|
{
|
|
Die();
|
|
}
|
|
}
|
|
|
|
private void Die()
|
|
{
|
|
Debug.Log($"{gameObject.name} je mŕtvy!");
|
|
Destroy(gameObject);
|
|
}
|
|
} |