Topic was automatically imported from the old Question2Answer platform.
Asked By
hermo
I want the player to keep a button pressed for 2 seconds. If success, something happens.
If not (the button is pressed for less than 2 seconds), something else happens.
How do you do that?
I’ve tried with timers, incremental variables, combining “if not press” within “if pressed” without success.
I would do this.
The success/fail happens only one time / button selection.
_on_Button_button_down() and _on_Button_button_up connected to the buttons’s signal.
$Timer is a timer node.
var is_down = false
var no_more = false
onready var timer = $Timer
func _ready():
timer.wait_time = 2
timer.one_shot = true
timer.autostart = false
func _physics_process(delta):
if no_more:
return
if is_down and timer.is_stopped():
no_more = true
success()
if !is_down and !timer.is_stopped():
timer.stop()
fail()
func _on_Button_button_down():
is_down = true
timer.start()
func _on_Button_button_up():
is_down = false
no_more = false