init
This commit is contained in:
30
scripts/unit.gd
Normal file
30
scripts/unit.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user