Godot Version
v4.2.1.stable.official [b09f793f5]
Question
i have a timer that functions in the level but i can’t stop, or save the time. How can i do that? Here is the code i have for the timer.
extends CanvasLayer
var time = GameManager.speedrun_time
var running = true
func _physics_process(delta):
if running:
time = float(time) + delta
update_ui()
func update_ui():
# Format time with two decimal places
var formatted_time = str(time)
var decimal_index = formatted_time.find(“.”)
if decimal_index > 0:
formatted_time = formatted_time.left(decimal_index + 3) # Take only two decimal places
GameManager.speedrun_time = formatted_time
$Label.text = formatted_time
func stop_timer():
running = false
update_ui() # Update UI with final time