extends CharacterBody3D class_name Enemy @onready var death_vfx_packed : PackedScene = preload("res://VFX/death_particles.tscn") @onready var sad_vfx_packed : PackedScene = preload("res://VFX/sad_particles.tscn") @export var speed : int = 2 @export var max_life : int = 10 var health : int = 0 : set(value): health = value if health >= max_life and is_alive: death() @onready var Path : PathFollow3D = get_parent() var is_alive : bool = true func _ready() -> void: $HealthBar3D.set_up(health, max_life) func _physics_process(delta: float) -> void: if !is_alive: return 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 $Sprite3D.visible = false var death_vfx : CPUParticles3D = death_vfx_packed.instantiate() get_tree().current_scene.add_child(death_vfx) death_vfx.global_position = global_position Path.queue_free()