Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SugarBeetle |
I’m trying to use a timer to make the players health lower by the second but I’m having trouble increasing their health (like picking up a potion).
This is the code for the health bar
extends Control
var health = 100
func _ready():
$bleed_timer.wait_time = health
$bleed_timer.start()
func life_change(health):
$ProgressBar.value = health
func _process(delta):
$ProgressBar.value = $bleed_timer.time_left
func _on_bleed_timer_timeout():
health -= 5
And this is what I put in the players script to make the health increase one an area is entered
func _on_interactionarea_body_entered(body):
if body.name == "blood pack":
$Camera2D/healthbar.health += 20
Is there a better way to do this or how can I achieve this? I want the players health to degrade by the second but increase when picking up an item yet the health still decreases after gaining the health.
Any help is welcomed, thank you.
You’ve explained what you’re trying to do, but not the actual problem you’re having with it (at least, I don’t see a problem explanation). Are you getting an error? Is the increase in health just not working (with no error)? Something else entirely?
Generally, the idea decreasing the health on a timer and increasing it when/where appropriate is perfectly fine.
jgodfrey | 2022-10-28 13:53