First, add the following to the top of the
signal shield_changed @export var max_shield = 100.0 @export var shield_regen = 5.0 var shield = 0: set = set_shield func set_shield(value): value = min(value, max_shield) shield = value shield_changed.emit(shield / max_shield) if shield <= 0: lives -= 1 explode()
shield variable works similarly to
lives, emitting a signal whenever it changes. Since the value will be added to by the shield’s regeneration, you need to make sure it doesn’t go above the
max_shield value. Then, when you emit the
shield_changed signal, you pass the ratio of
max_shield rather than...