20 lines
322 B
GDScript3
20 lines
322 B
GDScript3
|
extends CharacterBody2D
|
||
|
|
||
|
@export var health : int = 100
|
||
|
|
||
|
func _process(delta):
|
||
|
update_healthbar()
|
||
|
if health <= 0:
|
||
|
queue_free()
|
||
|
|
||
|
func update_healthbar():
|
||
|
$HealthBar.value = health
|
||
|
|
||
|
if health >= 100:
|
||
|
$HealthBar.visible = false
|
||
|
else:
|
||
|
$HealthBar.visible = true
|
||
|
|
||
|
func hit(damage : int):
|
||
|
health = health - damage
|