AbstractUnit for cross team compatibility
+ New folder in Scripts
This commit is contained in:
parent
385d8669b1
commit
f8e85d7134
18 changed files with 112 additions and 80 deletions
|
@ -1,62 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Unit))]
|
||||
public class HealthHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxHealth;
|
||||
[SerializeField] private float currentHealth;
|
||||
[SerializeField] private float armor;
|
||||
|
||||
private Unit _unit;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
_unit = GetComponent<Unit>();
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal");
|
||||
currentHealth -= Mathf.Max(0, damage-armor);
|
||||
if (currentHealth <= 0) Death();
|
||||
}
|
||||
|
||||
public void Heal(float value)
|
||||
{
|
||||
Debug.Assert(value >= 0, "value can't be less than zero");
|
||||
currentHealth = Mathf.Min(currentHealth + value, maxHealth);
|
||||
}
|
||||
|
||||
public float GetArmor()
|
||||
{
|
||||
return armor;
|
||||
}
|
||||
|
||||
public void EquipArmor(float armorBoost)
|
||||
{
|
||||
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use UnEquipArmor instead");
|
||||
armor += armorBoost;
|
||||
}
|
||||
|
||||
public void UnEquipArmor(float armorBoost)
|
||||
{
|
||||
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use EquipArmor instead");
|
||||
armor -= armorBoost;
|
||||
}
|
||||
|
||||
public void Death()
|
||||
{
|
||||
print("you dead");
|
||||
if (_unit.IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Remove(_unit);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Remove(_unit);
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue