Hittable

This component represents basic class of hittable entity (entity with HP, which can get damage, can be healed and killed).

We recommend to use it as base class for your characters in case if that characters should be able to get damage.

Protected fields (can be used from inherited class)

protected float currHealth;

Current health of hittable entity.

protected float maxHealth;

Max health of hittable entity.

protected TeamType teamType;

Team of this hittable object. TeamType.None by default.


Available methods

public void SetTeam(TeamType teamType)

This method assigns hittable object to certain team.


public virtual Transform GetHitTransform()

This method returns hit transform if this hittable. By default, its own transform is returned. Can be used for targeting enemy projectiles to this hittable entity.


public void GetDamage(float damage)

This method inflicts certain amount of damage to this hittable entity.


public void Heal(float amount)

This method applies certain amount of healing to this hittable entity.


public void Kill()

Instantly kills hittable entity.


public void ResetHealth()

Resets current health to max value.


public bool IsDead()

Returns true in case if entity is dead, otherwise false.


public float GetHPPercentage()

Returns current percentage of HP.


public float GetHP()

Returns current amount of HP.


public float GetMaxHP()

Returns max amount of HP.


public void SubscribeToDamageGot(UnityAction<float> onDamageGot)

This method adds listener to damage got event. If entity gets damage, given listener will be invoked.

Example:

character.SubscribeToDamageGot(damage =>
{
    FlyUpText ft = PoolSystem.GetInstanceAtPosition(combatTextPrefab, combatTextPrefab.GetName(), canvasTransform.position, canvasTransform);
    ft.SetColor(Color.red);
    ft.SetText($"-{Mathf.CeilToInt(damage)}");
    RefreshHPBar();
});

public void SubscribeToHealingGot(UnityAction<float> onHealingGot)

This method adds listener to healing got event. If entity gets healing, given listener will be invoked.


public void SubscribeToDeath(UnityAction onDeath)

This method adds listener to death event. If entity dies, given listener will be invoked.

Last updated