June 2018
Beginner to intermediate
298 pages
7h 38m
English
Here is the script for the HUD:
extends MarginContaineronready var life_counter = [$HBoxContainer/LifeCounter/L1, $HBoxContainer/LifeCounter/L2, $HBoxContainer/LifeCounter/L3, $HBoxContainer/LifeCounter/L4, $HBoxContainer/LifeCounter/L5]func _on_Player_life_changed(value): for heart in range(life_counter.size()): life_counter[heart].visible = value > heartfunc _on_score_changed(value): $HBoxContainer/ScoreLabel.text = str(value)
First, you make an array of references to the five heart indicators. Then, in _on_Player_life_changed(), which will be called when the player gets hurt or healed, you calculate how many hearts to display by setting visible to false if the number of the heart is less than the life amount.
_on_score_changed() ...
Read now
Unlock full access