63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using AsteroidGame.Interfaces;
|
|
using UnityEngine;
|
|
|
|
namespace AsteroidGame.Entities
|
|
{
|
|
public class EntityBase : MonoBehaviour, IDamageable, ITargetable
|
|
{
|
|
[Header("Health")]
|
|
[SerializeField] protected int _health;
|
|
[SerializeField] protected int _maxHealth;
|
|
[SerializeField] protected bool _isInvulnerable;
|
|
|
|
[Header("TargetPositions")]
|
|
[SerializeField] private Transform _centerPosition;
|
|
[SerializeField] private Transform _basePosition;
|
|
|
|
[Header("UI")]
|
|
[SerializeField] protected string _uiFriendlyName;
|
|
|
|
#region Props
|
|
|
|
public bool IsInvulnerable => _isInvulnerable;
|
|
public string UiFriendlyName => _uiFriendlyName;
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public void ModifyHealth(int healthChange)
|
|
{
|
|
if (!_isInvulnerable)
|
|
{
|
|
_health += healthChange;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Setters
|
|
|
|
public void SetHealth(int newHealth) => _health = newHealth;
|
|
|
|
public void SetMaxHealth(int newHealth) => _maxHealth = newHealth;
|
|
|
|
public void SetInvulnerable(bool newState) => _isInvulnerable = newState;
|
|
|
|
#endregion
|
|
|
|
#region Getters
|
|
|
|
public Vector3 GetCenterPosition() => _centerPosition.transform.position;
|
|
|
|
public Vector3 GetBasePosition() => _basePosition.transform.position;
|
|
|
|
public int GetHealth() => _health;
|
|
|
|
public int GetMaxHealth() => _maxHealth;
|
|
|
|
public float GetHealthFactor() => (float)_health / (float)_maxHealth;
|
|
|
|
#endregion
|
|
}
|
|
} |