forked from kanium/starcheese
30 lines
760 B
GDScript
30 lines
760 B
GDScript
extends Button
|
|
|
|
@onready var main_script = get_node("/root/Main")
|
|
|
|
func _ready():
|
|
# Connect the "pressed" signal to a custom function in this script
|
|
self.pressed.connect(self.on_button_pressed)
|
|
|
|
# Handle what happens when the button is pressed
|
|
func on_button_pressed():
|
|
# Call the main script's spawn_asteroid function
|
|
main_script.spawn_asteroid()
|
|
|
|
# Disable the button temporarily to prevent immediate re-trigger
|
|
self.disabled = true
|
|
|
|
self.release_focus()
|
|
|
|
# Start a timer to re-enable the button after 0.2 seconds
|
|
var timer = Timer.new()
|
|
timer.wait_time = 0.2
|
|
timer.one_shot = true
|
|
timer.timeout.connect(self.on_timeout)
|
|
add_child(timer)
|
|
timer.start()
|
|
|
|
# Re-enable the button when the timer times out
|
|
func on_timeout():
|
|
self.disabled = false
|