19 lines
293 B
GDScript
19 lines
293 B
GDScript
class_name HealthComponent
|
|
extends Node
|
|
|
|
signal value_changed
|
|
|
|
@export var max_value: float
|
|
var value: float
|
|
|
|
func _ready():
|
|
value = max_value
|
|
value_changed.emit()
|
|
|
|
func take_damage(attack: DamageInstance):
|
|
value -= attack.damage
|
|
value_changed.emit()
|
|
|
|
if value <= 0:
|
|
owner.queue_free()
|