Ctrl+K

HealthComponent

Declaration

public class Strawberry.Components.Lifecycle.HealthComponent

A component that manages the health of an entity and raises events when the health changes.

Inherits: Strawberry.Core.BaseComponent

Properties

Health

Gets or sets the amount of health the entity has, if it reaches 0 or less than 0, then the entity will be destroyed by the system and the KilledEvent will raise. (Default value is 100)

float Health { get set }

Invincible

Gets or sets a boolean that indicates whether the entity is invincible or not. If it's true, then the Damage method will do nothing. (Default value is false)

bool Invincible { get set }

MaxHealth

Gets or sets the maximum health the entity can have. (Default value is 100). If the Health is greater than MaxHealth, then it will be set to MaxHealth.

float MaxHealth { get set }

DestroyOnKill

Gets or sets whether the entity should be destroyed when it gets killed. (Default value is true)

bool DestroyOnKill { get set }

IsDead

Gets whether the entity is dead.

bool IsDead { get }

Methods

Heal

Heals the entity by the given amount.

void Heal(float amount)

Parameters:

Name Type Description
amount System.Single The amount to heal the entity by.

Damage

Damages the entity by the given amount. If the health is less than or equal to 0, it will invoke the KilledEvent and destroy the owner if DestroyOnKill is true.

void Damage(float amount)

Parameters:

Name Type Description
amount System.Single The amount to damage the entity by.