mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
24 lines
409 B
GDScript
24 lines
409 B
GDScript
extends Area3D
|
|
class_name HealthComponent
|
|
|
|
@export var max_health : int = 100
|
|
@export var health : int
|
|
|
|
signal health_zeroed
|
|
|
|
func _ready():
|
|
health = max_health
|
|
area_entered.connect(_on_area_entered)
|
|
|
|
func damage(amount : int):
|
|
health -= amount
|
|
if health <= 0:
|
|
health_zeroed.emit()
|
|
|
|
func reset():
|
|
health = max_health
|
|
|
|
func _on_area_entered(area):
|
|
if area is AreaDamageComponent:
|
|
damage(area.damage)
|