If you want to display hearts in UI, you can use HBoxContainer
or VBoxContainer
(based on direction of your healthbar). To add one heart you need to add new TextureRect
. To take one heart you can simply remove first child of box container (but make sure that you have hearts there).
Then to add heart:
var heart := TextureRect.new()
heart.texture = load("res://Textures/Heart.png")
boxcontainer.add_child(heart)
And to take heart:
if boxcontainer.get_child_count() > 0:
boxcontainer.get_child(0).queue_free()