From a10570d865106dcaf1037979cad1788da03e989d Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Sun, 29 Sep 2024 22:31:03 +0100 Subject: ui: Add UI to disply ammo and info toasts --- scripts/ui.gd | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/ui.gd (limited to 'scripts/ui.gd') diff --git a/scripts/ui.gd b/scripts/ui.gd new file mode 100644 index 0000000..eaf2d0c --- /dev/null +++ b/scripts/ui.gd @@ -0,0 +1,31 @@ +extends CanvasLayer + +@export var player: Node3D + +var timeout: float = 0 +var timeout_counter: float = 0 + +# Called when the node enters the scene tree for the first time. +#func _ready() -> void: +# pass # Replace with function body. + +func have_toast() -> bool: + return timeout > 0 + +func set_toast(text: String, p_timeout: float) -> void: + $Toast.text = text + + if p_timeout != 0: + timeout = p_timeout + timeout_counter = 0 + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + $Ammo.text = "Ammo " + str(player.ammo) + + if timeout > 0: + if timeout_counter < timeout: + timeout_counter += delta + else: + $Toast.text = "" + timeout = 0 -- cgit