I am currently making a health bar for my character. The problem is that when I add a reset function to health, the health resets properly, however I can't kill/squash the enemy from the top instead it results in game over. What can I do to fix this problem? Is this to do with the method I am adding when connecting the signal in my player script? . I am quite new to Godot, so feedback on this issue would be appreciated! Thank you. If you need more info then let me know!
Player script:
func ready():
stats.connect("nohealth", self, "reset")
Stats script:
extends Node
export var maxhealth = 1 setget setmaxhealth
var health = maxhealth setget set_health
signal nohealth
signal healthchanged(value)
signal maxhealthchanged(value)
func setmaxhealth(value):
maxhealth = value
self.health = min(health, maxhealth)
emitsignal("maxhealth_changed")
func sethealth(value):
health = value
emitsignal("healthchanged", health)
if health <= 0:
reset()
emitsignal("no_health")
func ready():
self.health = maxhealth
func reset():
health = 3
gettree().changescene("res://Game Over.tscn")
Enemy script:
func onHurtboxareaentered(area):
stats.health -= area.damage