The context for this can be seen in the related question.
This is in the Slime enemy scene. At the top of the script I put
signal Slime_attacked(damage)
This is in the _physics_process(delta: float)
func of the Slime scene.
if $AttackRaycast1.is_colliding() or $AttackRaycast2.is_colliding():
$AnimationPlayer.play("Attack")
emit_signal("Slime_attacked", damage)
This is in the script for the root node of the level scene where the player, hearts and enemy instances are:
var health: int = 6
func _ready():
$Background/AnimationPlayer.play("GameHeart1Full")
$Background/AnimationPlayer.play("GameHeart2Full")
$Background/AnimationPlayer.play("GameHeart3Full")
$Background.connect("Slime_attacked",$Enemies/Slime1,"_on_Slime_attacked")
And this is the signal func here:
func _on_Slime_attacked():
print("Boo")
health= health -1
if health == 6:
$Background/AnimationPlayer.play("GameHeart1Full")
$Background/AnimationPlayer.play("GameHeart2Full")
$Background/AnimationPlayer.play("GameHeart3Full")
I really have no experience with this side of Godot so some extra help to finish this would be amazing :)