19 lines
293 B
GDScript3
19 lines
293 B
GDScript3
|
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()
|