Created
July 11, 2023 23:00
-
-
Save default1200/5cfe2cb8eae54831bafdc868f85ad0ca to your computer and use it in GitHub Desktop.
Health.gd for progress bar help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
signal max_changed(new_max) | |
signal changed(new_amount) | |
export(int) var max_amount = 10 setget set_max | |
onready var current = max_amount setget set_current | |
func _ready(): | |
_initialize() | |
func set_max(new_max): | |
max_amount = new_max | |
max_amount = max(1, new_max) | |
emit_signal("max_changed", max_amount) | |
func set_current(new_value): | |
current = new_value | |
current = clamp(current, 0, max_amount) | |
emit_signal("changed", current) | |
if current == 0: | |
emit_signal("depleted") | |
func _initialize(): | |
emit_signal("max_changed", max_amount) | |
emit_signal("changed", current) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment