54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using AsteroidGame.Interfaces;
|
|
using UnityEngine;
|
|
|
|
namespace AsteroidGame.Entities
|
|
{
|
|
public class EntityBase : MonoBehaviour, IDamageable
|
|
{
|
|
[SerializeField] protected int health;
|
|
[SerializeField] protected int maxHealth;
|
|
[SerializeField] protected bool isInvulnerable;
|
|
|
|
public bool IsInvulnerable => isInvulnerable;
|
|
|
|
public void ModifyHealth(int healthChange)
|
|
{
|
|
if (!isInvulnerable)
|
|
{
|
|
health += healthChange;
|
|
}
|
|
}
|
|
|
|
public void SetHealth(int newHealth)
|
|
{
|
|
health = newHealth;
|
|
}
|
|
|
|
public void SetMaxHealth(int newHealth)
|
|
{
|
|
maxHealth = newHealth;
|
|
}
|
|
|
|
public void SetInvulnerable(bool newState)
|
|
{
|
|
isInvulnerable = newState;
|
|
}
|
|
|
|
public int GetHealth()
|
|
{
|
|
return health;
|
|
}
|
|
|
|
public int GetMaxHealth()
|
|
{
|
|
return maxHealth;
|
|
}
|
|
|
|
public float GetHealthFactor()
|
|
{
|
|
// ReSharper disable once PossibleLossOfFraction
|
|
return health / maxHealth;
|
|
}
|
|
}
|
|
}
|