31 lines
600 B
GDScript
31 lines
600 B
GDScript
extends CharacterBody3D
|
|
class_name Unit
|
|
|
|
# Базовый класс для всех юнитов (игрок и противники)
|
|
|
|
@export var speed: float = 5.0
|
|
@export var health: float = 100.0
|
|
@export var max_health: float = 100.0
|
|
|
|
signal health_changed(new_health: float)
|
|
signal died
|
|
|
|
func _ready():
|
|
health = max_health
|
|
|
|
func take_damage(amount: float):
|
|
health -= amount
|
|
health = max(0, health)
|
|
health_changed.emit(health)
|
|
|
|
if health <= 0:
|
|
die()
|
|
|
|
func die():
|
|
died.emit()
|
|
queue_free()
|
|
|
|
func _physics_process(delta):
|
|
# Базовая физика движения
|
|
move_and_slide()
|