Added a loot component
This commit is contained in:
@ -2,6 +2,9 @@ class_name HealthComponent
|
||||
extends Node
|
||||
|
||||
signal value_changed
|
||||
signal death
|
||||
|
||||
const DEATH_THRESHOLD = 0.01
|
||||
|
||||
@export var max_value: float
|
||||
var value: float
|
||||
@ -11,8 +14,8 @@ func _ready():
|
||||
value_changed.emit()
|
||||
|
||||
func take_damage(attack: DamageInstance):
|
||||
value -= attack.damage
|
||||
value = clampf(value - attack.damage, 0, max_value)
|
||||
value_changed.emit()
|
||||
|
||||
if value <= 0:
|
||||
owner.queue_free()
|
||||
if value < DEATH_THRESHOLD:
|
||||
death.emit()
|
||||
|
Reference in New Issue
Block a user