extends CharacterBody3D
class_name Enemy

@export var speed : int = 2
@export var health : int = 15 :
	set(value):
		health = value
		if health <= 0 and is_alive:
			death()

@onready var Path : PathFollow3D = get_parent()
var is_alive : bool = true

#func _ready() -> void:
	#$HealthBar3D.set_up(health)


func _physics_process(delta: float) -> void:
	Path.set_progress(Path.get_progress() + speed * delta)
	
	if Path.get_progress_ratio() >= 0.99:
		#Global.health -= 20
		death()


func take_damage(damage : int) -> void:
	health -= damage
	#$HealthBar3D.update(health)


func death() -> void:
	is_alive = false
	#Global.enemies_alive -= 1
	#Global.money += 50
	Path.queue_free()
