31 lines
588 B
C#
31 lines
588 B
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class EnemyHealth : MonoBehaviour
|
||
|
|
{
|
||
|
|
[SerializeField] int maxHealth = 100;
|
||
|
|
int currentHealth;
|
||
|
|
void Awake()
|
||
|
|
{
|
||
|
|
currentHealth = maxHealth;
|
||
|
|
}
|
||
|
|
public void TakeDamage(int damage)
|
||
|
|
{
|
||
|
|
currentHealth -= damage;
|
||
|
|
if (currentHealth <= 0)
|
||
|
|
{
|
||
|
|
gameObject.SetActive(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|