22 lines
429 B
GDScript3
22 lines
429 B
GDScript3
|
|
extends HBoxContainer
|
||
|
|
|
||
|
|
@export var initial_health : int = 5
|
||
|
|
@export var packedHeart : PackedScene;
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
for i in range(initial_health):
|
||
|
|
add_child(packedHeart.instantiate())
|
||
|
|
|
||
|
|
func set_health(health : int):
|
||
|
|
var i = 0
|
||
|
|
for heart : Heart in get_children():
|
||
|
|
i += 1
|
||
|
|
if i <= health:
|
||
|
|
heart.restore()
|
||
|
|
else:
|
||
|
|
heart.fade()
|
||
|
|
|
||
|
|
|
||
|
|
func _on_player_health_changed(new_health: int) -> void:
|
||
|
|
set_health(new_health)
|