SolokNightAdventures/scripts/healthbar.gd
2025-02-15 15:36:27 +01:00

34 lines
661 B
GDScript

extends ProgressBar
@onready var label: Label = $Label
@onready var damagebar: ProgressBar = $Damagebar
@onready var timer: Timer = $Timer
var health = 0 : set = _set_health
func _set_health(new_health):
var prev_health = health
health = min(max_value, new_health)
value = health
label.text = str(health)
if health <= 0:
queue_free()
if health < prev_health:
timer.start()
elif !timer.is_stopped():
pass
else: damagebar.value = health
func init_health(_health):
health = _health
max_value = health
value = health
damagebar.max_value = health
damagebar.value = health
func _on_timer_timeout() -> void:
damagebar.value = health